xref: /PHP-7.0/ext/recode/tests/002.phpt (revision c98b88aa)
1--TEST--
2recode_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
7function 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
17$html_file = fopen(realpath(dirname(__FILE__)) . '/html.raw', 'r');
18$utf_8_filepath = realpath(dirname(__FILE__)) . '/utf8.raw';
19$utf_8_file = fopen($utf_8_filepath, 'w+');
20
21recode_file('html..utf8', $html_file, $utf_8_file);
22
23rewind($utf_8_file);
24echo '#' . ascii2hex(fread($utf_8_file, filesize($utf_8_filepath))) . "#\n";
25
26fclose($html_file);
27fclose($utf_8_file);
28
29unlink($utf_8_filepath);
30?>
31--EXPECT--
32#31 32 33 c3 a5 c3 a4 c3 b6 61 62 63 #
33