<div class="cnblogs_code">
utf8_unicode( = = = 1</span><span style="color: #0000ff;">for</span> (<span style="color: #800080;">$i</span> = 0; <span style="color: #800080;">$i</span> < <span style="color: #008080;">strlen</span>( <span style="color: #800080;">$str</span> ); <span style="color: #800080;">$i</span>++<span style="color: #000000;"> ) {
</span><span style="color: #800080;">$thisValue</span> = <span style="color: #008080;">ord</span>( <span style="color: #800080;">$str</span>[ <span style="color: #800080;">$i</span><span style="color: #000000;"> ] );
</span><span style="color: #0000ff;">if</span> ( <span style="color: #800080;">$thisValue</span> < <span style="color: #008080;">ord</span>('A'<span style="color: #000000;">) ) {
</span><span style="color: #008000;">//</span><span style="color: #008000;"> exclude 0-9</span>
<span style="color: #0000ff;">if</span> (<span style="color: #800080;">$thisValue</span> >= <span style="color: #008080;">ord</span>('0') && <span style="color: #800080;">$thisValue</span> <= <span style="color: #008080;">ord</span>('9'<span style="color: #000000;">)) {
</span><span style="color: #008000;">//</span><span style="color: #008000;"> number</span>
<span style="color: #800080;">$unicode</span>[] = <span style="color: #008080;">chr</span>(<span style="color: #800080;">$thisValue</span><span style="color: #000000;">);
}
</span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
</span><span style="color: #800080;">$unicode</span>[] = '%'.<span style="color: #008080;">dechex</span>(<span style="color: #800080;">$thisValue</span><span style="color: #000000;">);
}
} </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
</span><span style="color: #0000ff;">if</span> ( <span style="color: #800080;">$thisValue</span> < 128<span style="color: #000000;">) {
</span><span style="color: #800080;">$unicode</span>[] = <span style="color: #800080;">$str</span>[ <span style="color: #800080;">$i</span><span style="color: #000000;"> ];
} </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
</span><span style="color: #0000ff;">if</span> ( <span style="color: #008080;">count</span>( <span style="color: #800080;">$values</span> ) == 0<span style="color: #000000;"> ) {
</span><span style="color: #800080;">$lookingFor</span> = ( <span style="color: #800080;">$thisValue</span> < 224 ) ? 2 : 3<span style="color: #000000;">;
}
</span><span style="color: #800080;">$values</span>[] = <span style="color: #800080;">$thisValue</span><span style="color: #000000;">;
</span><span style="color: #0000ff;">if</span> ( <span style="color: #008080;">count</span>( <span style="color: #800080;">$values</span> ) == <span style="color: #800080;">$lookingFor</span><span style="color: #000000;"> ) {
</span><span style="color: #800080;">$number</span> = ( <span style="color: #800080;">$lookingFor</span> == 3 ) ?<span style="color: #000000;">
( ( </span><span style="color: #800080;">$values</span>[0] % 16 ) * 4096 ) + ( ( <span style="color: #800080;">$values</span>[1] % 64 ) * 64 ) + ( <span style="color: #800080;">$values</span>[2] % 64 ):<span style="color: #000000;">
( ( </span><span style="color: #800080;">$values</span>[0] % 32 ) * 64 ) + ( <span style="color: #800080;">$values</span>[1] % 64<span style="color: #000000;"> );
</span><span style="color: #800080;">$number</span> = <span style="color: #008080;">dechex</span>(<span style="color: #800080;">$number</span><span style="color: #000000;">);
</span><span style="color: #800080;">$unicode</span>[] = (<span style="color: #008080;">strlen</span>(<span style="color: #800080;">$number</span>)==3)?"\u0".<span style="color: #800080;">$number</span>:"\u".<span style="color: #800080;">$number</span><span style="color: #000000;">;
</span><span style="color: #800080;">$values</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
</span><span style="color: #800080;">$lookingFor</span> = 1<span style="color: #000000;">;
} </span><span style="color: #008000;">//</span><span style="color: #008000;"> if</span>
} <span style="color: #008000;">//</span><span style="color: #008000;"> if</span>
<span style="color: #000000;"> }
} <span style="color: #008000;">//<span style="color: #008000;"> for
<span style="color: #0000ff;">return <span style="color: #008080;">implode("",<span style="color: #800080;">$unicode<span style="color: #000000;">);
}