002.phpt 866 B

1234567891011121314151617181920212223242526272829303132
  1. --TEST--
  2. recode_string() function - Testing string conversions between latin1, UTF-8 and html
  3. --SKIPIF--
  4. <?php if (!extension_loaded("recode")) print "skip"; ?>
  5. --FILE--
  6. <?php
  7. function ascii2hex($ascii) {
  8. $hex = '';
  9. for ($i = 0; $i < strlen($ascii); $i++) {
  10. $byte = dechex(ord($ascii{$i}));
  11. $byte = str_repeat('0', 2 - strlen($byte)).$byte;
  12. $hex .= $byte . " ";
  13. }
  14. return $hex;
  15. }
  16. $html_file = fopen(realpath(dirname(__FILE__)) . '/html.raw', 'r');
  17. $utf_8_filepath = realpath(dirname(__FILE__)) . '/utf8.raw';
  18. $utf_8_file = fopen($utf_8_filepath, 'w+');
  19. recode_file('html..utf8', $html_file, $utf_8_file);
  20. rewind($utf_8_file);
  21. echo '#' . ascii2hex(fread($utf_8_file, filesize($utf_8_filepath))) . "#\n";
  22. fclose($html_file);
  23. fclose($utf_8_file);
  24. unlink($utf_8_filepath);
  25. ?>
  26. --EXPECT--
  27. #31 32 33 c3 a5 c3 a4 c3 b6 61 62 63 #