-
Notifications
You must be signed in to change notification settings - Fork 1
/
utf8_2web.php
73 lines (68 loc) · 2.37 KB
/
utf8_2web.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE HTML >
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ascii2htmlcode</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
</head>
<body>
<pre>
<?php
include 'function.php';
/*
* open a nfo file and translate it into htmlcode
*/
$testfile='test/hey4.nfo';
$filesize =filesize($testfile);
$fhandle = fopen($testfile,'r');
$thebytes = fread($fhandle, $filesize);
fclose($fhandle);
for($c=0;$c<$filesize;$c++){ // cyctle through the whole file doing a byte at a time.
$byte=$thebytes[$c]; // get byte to process
$bits=byte2bin($byte);
// how many bytes in utf character
if ($bits[0]==0){ // just the 2 byte
echo '&#'.ord($byte).';';
}
else { // more than 1 byte
if ($bits[2]==0){ // two bytes utf 110
$umm0=$bits[3].$bits[4].$bits[5].$bits[6].$bits[7];
$c++;
$bits=byte2bin($thebytes[$c]);
$umm1=$bits[2].$bits[3].$bits[4].$bits[5].$bits[6].$bits[7];
$umm=$umm0.$umm1;
echo '&#'.bindec($umm).';';
}
else {
if ($bits[3]==0){ // three bytes
$umm0=$bits[4].$bits[5].$bits[6].$bits[7];
$c++;
$bits=byte2bin($thebytes[$c]);
$umm1=$bits[2].$bits[3].$bits[4].$bits[5].$bits[6].$bits[7];
$c++;
$bits=byte2bin($thebytes[$c]);
$umm2=$bits[2].$bits[3].$bits[4].$bits[5].$bits[6].$bits[7];
$umm=$umm0.$umm1.$umm2;
echo '&#'.bindec($umm).';';
}
else {
if ($bits[4]==0){ // four bytes
$umm0=$bits[5].$bits[6].$bits[7];
$c++;
$bits=byte2bin($thebytes[$c]);
$umm1=$bits[2].$bits[3].$bits[4].$bits[5].$bits[6].$bits[7];
$c++;
$bits=byte2bin($thebytes[$c]);
$umm2=$bits[2].$bits[3].$bits[4].$bits[5].$bits[6].$bits[7];
$c++;
$bits=byte2bin($thebytes[$c]);
$umm3=$bits[2].$bits[3].$bits[4].$bits[5].$bits[6].$bits[7];
$umm=$umm0.$umm1.$umm2.$umm3;
echo '&#'.bindec($umm).';';
}
}
}
}
}
?>
</pre>