使用php将Html实体还原为特殊字符
我想将特殊字符转换为HTML实体,然后再转换回原始字符 我使用了使用php将Html实体还原为特殊字符,php,html-entities,html-encode,Php,Html Entities,Html Encode,我想将特殊字符转换为HTML实体,然后再转换回原始字符 我使用了htmlentities()和html\u entity\u decode()。它对我来说很好,但是{和}没有回到原始字符,它们仍然是{和} 我现在能做什么 我的代码如下所示: $custom_header = htmlentities($custom_header); $custom_header = html_entity_decode($custom_header); 即使没有人可以复制你的问题,这里有一个直
htmlentities()
和html\u entity\u decode()
。它对我来说很好,但是{
和}
没有回到原始字符,它们仍然是{代码>和}代码>
我现在能做什么
我的代码如下所示:
$custom_header = htmlentities($custom_header);
$custom_header = html_entity_decode($custom_header);
即使没有人可以复制你的问题,这里有一个直接的方法来解决它,一个简单的方法
调用htmlentities
将&
编码为&代码>,它将为您提供字符串
"{hello}"
&代码>随后被解码回&
,以输出:
"{hello}"
修复方法是再次通过html\u entity\u decode
发送字符串,这将正确解码实体
$custom_header = "{hello}";
$custom_header = htmlentities($custom_header);
$custom_header = html_entity_decode($custom_header);
echo html_entity_decode( $custom_header); // Outputs {hello}
无法复制。请提供一个完整的示例来演示此行为。我的$custom_标题类似于此$(文档)。就绪(函数(){;$(“#左侧#u自定义_图像”)。单击(函数(){;警报(“HELLO”)};};) 因此,您正在对包含{解码时返回到{代码>?那是。。。期待。请按照链接,请帮我一个忙。我要{;从另一个角度来看,{我的jquery代码不起作用。它看起来像是完全相同的字符串,请参阅此粘贴,它输出一个bin2hex的{}“
:谢谢您的回答,但是如果以后有其他字符包含而这次不包含?我如何才能编写此类字符的完整替换代码?@user1044804-我已编辑了我的解决方案,为您最近的粘贴添加了修复程序。
"{hello}"
$custom_header = "{hello}";
$custom_header = htmlentities($custom_header);
$custom_header = html_entity_decode($custom_header);
echo html_entity_decode( $custom_header); // Outputs {hello}