問題描述
如何更換:
- ?"與a"
- é"與e"
在 PHP 中?這可能嗎?我在某處讀到過,我可以用基本字符的 ascii 值和重音的 ascii 值進(jìn)行一些數(shù)學(xué)計(jì)算,但我現(xiàn)在找不到任何參考資料.
in PHP? Is this possible? I've read somewhere I could do some math with the ascii value of the base character and the ascii value of the accent, but I can't find any references now.
推薦答案
此答案不正確.我寫的時(shí)候不理解 Unicode Normalization.看 francadaval 的評(píng)論和鏈接
查看 Normalizer 類來執(zhí)行此操作.文檔很好,所以我只是鏈接它而不是在這里重復(fù):
Check out the Normalizer class to do this. The documentation is good, so I'll just link it instead of repeating things here:
http://www.php.net/manual/en/class.normalizer.php
具體來說,該類的 normalize 成員:
Specifically, the normalize member of that class:
http://www.php.net/manual/en/normalizer.normalize.php
請(qǐng)注意,Unicode 規(guī)范化有多種形式,您似乎想要規(guī)范化形式 KD (NFKD) 兼容性分解,但您應(yīng)該閱讀文檔以確保.
Note that Unicode normalization has several forms, and you seem to want Normalization Form KD (NFKD) Compatibility Decomposition, though you should read the documentation to make sure.
您不應(yīng)該嘗試為此推出自己的函數(shù):可能出錯(cuò)的事情太多了,使用提供的函數(shù)是一個(gè)更好的主意.
You shouldn't try to roll your own function for this: There's way too many things that can go wrong, and using the provided function is a much better idea.
這篇關(guān)于如何用它們?cè)?PHP 中基于的特殊字符替換特殊字符?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!