File tree 3 files changed +71
-0
lines changed
3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
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
+
17
+ function 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
+
31
+ echo "# " . $ utf8_hex . "# \n" ;
32
+ echo "# " . $ html . "# \n" ;
33
+ echo "# " . $ lat1_hex . "# \n" ;
34
+ ?>
35
+ --EXPECT--
36
+ #31 32 33 c3 a5 c3 a4 c3 b6 61 62 63 #
37
+ #123åäöabc#
38
+ #31 32 33 e5 e4 f6 61 62 63 #
Original file line number Diff line number Diff line change
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
+
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
+
21
+ recode_file ('html..utf8 ' , $ html_file , $ utf_8_file );
22
+
23
+ rewind ($ utf_8_file );
24
+ echo '# ' . ascii2hex (fread ($ utf_8_file , filesize ($ utf_8_filepath ))) . "# \n" ;
25
+
26
+ fclose ($ html_file );
27
+ fclose ($ utf_8_file );
28
+
29
+ unlink ($ utf_8_filepath );
30
+ ?>
31
+ --EXPECT--
32
+ #31 32 33 c3 a5 c3 a4 c3 b6 61 62 63 #
Original file line number Diff line number Diff line change
1
+ 123åäöabc
You can’t perform that action at this time.
0 commit comments