xref: /PHP-5.6/ext/standard/tests/math/bug30695.phpt (revision b6f9b5c6)
1--TEST--
2Bug #30695 (32 bit issues)
3--FILE--
4<?php
5	function toUTF8( $char_code )
6    {
7        switch ( $char_code )
8        {
9            case 0:
10                $char = chr( 0 );
11            case !($char_code & 0xffffff80): // 7 bit
12                $char = chr( $char_code );
13                break;
14            case !($char_code & 0xfffff800): // 11 bit
15                $char = ( chr(0xc0 | (($char_code >> 6) & 0x1f)) .
16                          chr(0x80 | ($char_code & 0x3f)) );
17                break;
18            case !($char_code & 0xffff0000): // 16 bit
19                $char = ( chr(0xe0 | (($char_code >> 12) & 0x0f)) .
20                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
21                          chr(0x80 | ($char_code & 0x3f)) );
22                break;
23            case !($char_code & 0xffe00000): // 21 bit
24                $char = ( chr(0xf0 | (($char_code >> 18) & 0x07)) .
25                          chr(0x80 | (($char_code >> 12) & 0x3f)) .
26                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
27                          chr(0x80 | ($char_code & 0x3f)) );
28                break;
29            case !($char_code & 0xfc000000): // 26 bit
30                $char = ( chr(0xf8 | (($char_code >> 24) & 0x03)) .
31                          chr(0x80 | (($char_code >> 18) & 0x3f)) .
32                          chr(0x80 | (($char_code >> 12) & 0x3f)) .
33                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
34                          chr(0x80 | ($char_code & 0x3f)) );
35            default: // 31 bit
36                $char = ( chr(0xfc | (($char_code >> 30) & 0x01)) .
37                          chr(0x80 | (($char_code >> 24) & 0x3f)) .
38                          chr(0x80 | (($char_code >> 18) & 0x3f)) .
39                          chr(0x80 | (($char_code >> 12) & 0x3f)) .
40                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
41                          chr(0x80 | ($char_code & 0x3f)) );
42        }
43        return $char;
44    }
45
46
47	echo "\n", toUTF8(65), "\n", toUTF8(233), "\n", toUTF8(1252), "\n", toUTF8(20095), "\n";
48?>
49--EXPECT--
50
51A
52é
53Ӥ
54乿
55