php functions to help you get out of unicode hell.
function bpad ($instr) {
return substr("000000", 0, 8 - strlen($instr)) . $instr;
}
function dpad ($instr) {
return substr(" ", 0, 3 - strlen($instr)) . $instr;
}
function show($instr) {
for ($i = 0; $i < strlen($instr); $i++) {
$let = $instr[$i];
$no = ord($let);
echo $i . " : " . $let . " / " . dpad($no) . " / " . bpad(decbin($no)) . " / " . dechex($no). "\n";
}
}
Here is an example of use
php > $var = "T" . pack("cc", 195, 171) . "st";
php > show($var);
0 : T / 84 / 01010100 / 54
1 : � / 195 / 11000011 / c3
2 : � / 171 / 10101011 / ab
3 : s / 115 / 01110011 / 73
4 : t / 116 / 01110100 / 74
php > show (utf8_decode($var));
0 : T / 84 / 01010100 / 54
1 : � / 235 / 11101011 / eb
2 : s / 115 / 01110011 / 73
3 : t / 116 / 01110100 / 74
Advertisement