Voting

: two minus one?
(Example: nine)

The Note You're Voting On

zhawari at hotmail dot com
19 years ago
Here is how to convert UTF-8 numbers to UCS-2 numbers in hex:

<?php

function utf8toucs2($str)
{
for (
$i=0;$i<strlen($str);$i+=2)
{
$substring1 = $str[$i].$str[$i+1];
$substring2 = $str[$i+2].$str[$i+3];

if (
hexdec($substring1) < 127)
$results = "00".$str[$i].$str[$i+1];
else
{
$results = dechex((hexdec($substring1)-192)*64 + (hexdec($substring2)-128));
if (
$results < 1000) $results = "0".$results;
$i+=2;
}
$ucs2 .= $results;
}
return
$ucs2;
}

echo
strtoupper(utf8toucs2("D985D8B1D8AD"))."\n";
echo
strtoupper(utf8toucs2("456725"))."\n";

?>

Input:
D985D8B1D8AD
Output:
06450631062D

Input:
456725
Output:
004500670025

<< Back to user notes page

To Top