other_encodings.phpt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. Test of oddball text encodings which are not tested elsewhere
  3. --EXTENSIONS--
  4. mbstring
  5. --SKIPIF--
  6. <?php
  7. if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
  8. ?>
  9. --FILE--
  10. <?php
  11. mb_substitute_character(0x25);
  12. // "7bit". This is not a real text encoding.
  13. var_dump(mb_convert_encoding("ABC", "7bit", "ASCII"));
  14. var_dump(mb_convert_encoding("\x80", "7bit", "ASCII"));
  15. var_dump(mb_convert_encoding("ABC", "8bit", "7bit"));
  16. var_dump(mb_check_encoding(chr(255), '7bit'));
  17. echo "7bit done\n";
  18. // "8bit"
  19. var_dump(mb_convert_encoding("\x01\x00", "8bit", "UTF-16BE")); // codepoints over 0xFF are illegal for '8-bit'
  20. echo "8bit done\n";
  21. // UCS-2
  22. echo bin2hex(mb_convert_encoding("\xFF\xFE\x00\x30", "UTF-16BE", "UCS-2")), "\n";
  23. echo bin2hex(mb_convert_encoding("\xFE\xFF\x30\x00", "UTF-16BE", "UCS-2")), "\n";
  24. echo bin2hex(mb_convert_encoding("\x00\x30", "UTF-16BE", "UCS-2LE")), "\n";
  25. echo "UCS-2 done\n";
  26. // UCS-4
  27. echo bin2hex(mb_convert_encoding("\xFF\xFE\x00\x00\x00\x30\x00\x00", "UTF-16BE", "UCS-4")), "\n";
  28. echo bin2hex(mb_convert_encoding("\x00\x00\xFE\xFF\x00\x00\x30\x01", "UTF-16BE", "UCS-4")), "\n";
  29. echo bin2hex(mb_convert_encoding("\x02\x30\x00\x00", "UTF-16BE", "UCS-4LE")), "\n";
  30. echo bin2hex(mb_convert_encoding("\x00\x00\x30\x03", "UTF-16BE", "UCS-4BE")), "\n";
  31. mb_substitute_character("long");
  32. echo mb_convert_encoding("\x01\x02\x03", "UTF-8", "UCS-4"), "\n";
  33. echo "UCS-4 done\n";
  34. ?>
  35. --EXPECT--
  36. string(3) "ABC"
  37. string(1) "%"
  38. string(3) "ABC"
  39. bool(false)
  40. 7bit done
  41. string(1) "%"
  42. 8bit done
  43. 3000
  44. 3000
  45. 3000
  46. UCS-2 done
  47. 3000
  48. 3001
  49. 3002
  50. 3003
  51. %
  52. UCS-4 done