PHP ord() function on extended ASCII table

好久不见. 提交于 2019-12-06 03:03:58

ord() does not supports utf-8. Use this function for unicode characters:

function uniord($u) { 
    $k = mb_convert_encoding($u, 'UCS-2LE', 'UTF-8'); 
    $k1 = ord(substr($k, 0, 1)); 
    $k2 = ord(substr($k, 1, 1)); 
    return $k2 * 256 + $k1; 
} 

    echo ord('!'); // prints 33 : OK
    echo ord('a'); // prints 97 : OK

    echo uniord('é'); //233
    echo uniord('ü'); //252

PS: you can use uniord() for both type of characters perfectly.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!