bug30695.phpt 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --TEST--
  2. Bug #30695 (32 bit issues)
  3. --SKIPIF--
  4. <?php
  5. if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
  6. ?>
  7. --FILE--
  8. <?php
  9. function toUTF8( $char_code )
  10. {
  11. switch ( $char_code )
  12. {
  13. case 0:
  14. $char = chr( 0 );
  15. break;
  16. case !($char_code & 0xffffff80): // 7 bit
  17. $char = chr( $char_code );
  18. break;
  19. case !($char_code & 0xfffff800): // 11 bit
  20. $char = ( chr(0xc0 | (($char_code >> 6) & 0x1f)) .
  21. chr(0x80 | ($char_code & 0x3f)) );
  22. break;
  23. case !($char_code & 0xffff0000): // 16 bit
  24. $char = ( chr(0xe0 | (($char_code >> 12) & 0x0f)) .
  25. chr(0x80 | (($char_code >> 6) & 0x3f)) .
  26. chr(0x80 | ($char_code & 0x3f)) );
  27. break;
  28. case !($char_code & 0xffe00000): // 21 bit
  29. $char = ( chr(0xf0 | (($char_code >> 18) & 0x07)) .
  30. chr(0x80 | (($char_code >> 12) & 0x3f)) .
  31. chr(0x80 | (($char_code >> 6) & 0x3f)) .
  32. chr(0x80 | ($char_code & 0x3f)) );
  33. break;
  34. case !($char_code & 0xfc000000): // 26 bit
  35. $char = ( chr(0xf8 | (($char_code >> 24) & 0x03)) .
  36. chr(0x80 | (($char_code >> 18) & 0x3f)) .
  37. chr(0x80 | (($char_code >> 12) & 0x3f)) .
  38. chr(0x80 | (($char_code >> 6) & 0x3f)) .
  39. chr(0x80 | ($char_code & 0x3f)) );
  40. break;
  41. default: // 31 bit
  42. $char = ( chr(0xfc | (($char_code >> 30) & 0x01)) .
  43. chr(0x80 | (($char_code >> 24) & 0x3f)) .
  44. chr(0x80 | (($char_code >> 18) & 0x3f)) .
  45. chr(0x80 | (($char_code >> 12) & 0x3f)) .
  46. chr(0x80 | (($char_code >> 6) & 0x3f)) .
  47. chr(0x80 | ($char_code & 0x3f)) );
  48. }
  49. return $char;
  50. }
  51. echo "\n", toUTF8(65), "\n", toUTF8(233), "\n", toUTF8(1252), "\n", toUTF8(20095), "\n";
  52. ?>
  53. --EXPECTF--
  54. Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
  55. A
  56. Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
  57. Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d
  58. é
  59. Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
  60. Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d
  61. Ӥ
  62. Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
  63. Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d
  64. Deprecated: Implicit conversion from float 4294901760 to int loses precision in %s on line %d
  65. 乿