本文介紹了PHP 中 ord 或 charCodeAt() 的 UTF-8 安全等價物的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我需要能夠使用 ord() 獲得與 javascript 的 charCodeAt() 函數相同的值.問題是 ord() 不支持 UTF8.
I need to be able to use ord() to get the same value as javascript's charCodeAt() function. The problem is that ord() doesn't support UTF8.
如何在 PHP 中將 ? 轉換為 260?我嘗試了一些 uniord 函數,但它們都報告 256 而不是 260.
How can I get ? to translate to 260 in PHP? I've tried some uniord functions out there, but they all report 256 instead of 260.
非常感謝您的幫助!
問候
推薦答案
ord()
以字節為單位工作(作為大多數 PHP 標準字符串函數 - 如果不是全部).您需要自己轉換它,例如在多字節字符串擴展的幫助下:
ord()
works byte per byte (as most of PHPs standard string functions - if not all). You would need to convert it your own, for example with the help of the multibyte string extension:
$utf8Character = '?';
list(, $ord) = unpack('N', mb_convert_encoding($utf8Character, 'UCS-4BE', 'UTF-8'));
echo $ord; # 260
這篇關于PHP 中 ord 或 charCodeAt() 的 UTF-8 安全等價物的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!