xref: /PHP-7.0/ext/recode/tests/001.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
17function hex2ascii($hex){
18    $ascii='';
19    $hex=str_replace(" ", "", $hex);
20    for($i=0; $i<strlen($hex); $i=$i+2) {
21        $ascii .= chr(hexdec(substr($hex, $i, 2)));
22    }
23    return($ascii);
24}
25
26$lat1_hex_org = '31 32 33 e5 e4 f6 61 62 63';
27$utf8_hex = ascii2hex(recode_string('lat1..utf-8', hex2ascii($lat1_hex_org)));
28$html = recode_string('utf-8..html', hex2ascii($utf8_hex));
29$lat1_hex = ascii2hex(recode_string('html..lat1', $html));
30
31echo "#" . $utf8_hex . "#\n";
32echo "#" . $html . "#\n";
33echo "#" . $lat1_hex . "#\n";
34?>
35--EXPECT--
36#31 32 33 c3 a5 c3 a4 c3 b6 61 62 63 #
37#123&aring;&auml;&ouml;abc#
38#31 32 33 e5 e4 f6 61 62 63 #