问题描述
在PHP中,当我读取数据时,假设数据(字符串块)包含HTML特殊字符DECIMAL HEX代码,如:
这是一个带有& amp ;#X153;和š
我们可以说上面的HEX代码是它的对应符号的源代码,并且这些代码将被渲染为正确的符号在浏览器中。
但是我想要做的是,对于这些字符(例如),我想要这些HEX(es)作为转换的原始字符符号,如:
这是一个带有œ和š
的示例字符串。那么,我该如何检测十进制十六进制代码在一个字符串中并将它们转换成最终符号,而不是保留十六进制代码?
注意:
For更多clearence,是否有任何功能检测和转换十六进制到符号?
赞:
œ
=> - >
š
=> <
$ s = &#x153;和&#x161;;
echo html_entity_decode($ s,ENT_COMPAT,'UTF-8');
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:œ
=> œ
š
=> š
$s = "This is a sample string with œ and š";
echo html_entity_decode($s, ENT_COMPAT, 'UTF-8');
这篇关于PHP来检测和转换特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!