Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php将Html实体还原为特殊字符_Php_Html Entities_Html Encode - Fatal编程技术网

使用php将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); 即使没有人可以复制你的问题,这里有一个直

我想将特殊字符转换为HTML实体,然后再转换回原始字符

我使用了
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}