PHP to detect and convert Special Characters?

烂漫一生 提交于 2019-12-11 03:07:41

问题


In PHP when i read the Data, let say the data (chunks of strings) is containing HTML Special Character DECIMAL HEX Codes like:
This is a sample string with œ and š

We can say above HEX codes are the source codes of its correspondence Symbol and these will be rendered as correct Symbols in Browser.

But what i want to do is, for these characters (for example), i want these HEX(es) as the converted original Character Symbols like:
This is a sample string with œ and š

So how can i detect the any of decimal HEX Codes inside a string and convert each of them into final Symbol(s), instead of keeping HEX codes?

Note:
For more clearence, is there any function to detect and convert the Hex to Symbol?
Like:
œ => œ
š => š


回答1:


$s = "This is a sample string with œ and š";
echo html_entity_decode($s, ENT_COMPAT, 'UTF-8');



回答2:


Those are HTML entities - you can go back to actual symbol with html_entity_decode().




回答3:


make sure anything you use (database tables, json or xml for data exchange, html files etc etc etc) is in UTF-8 format



来源:https://stackoverflow.com/questions/12334022/php-to-detect-and-convert-special-characters

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