我有这个字符串:
<p>This is a test</p>rn<p><strong>this is a test</strong></p>
所以我试着把原始的字符串转换成HTML。
我试过了:
echo ' <h4><b>Din besvarelse</b></h4>
<text style="word-wrap: break-word; height:auto;">
'.htmlspecialchars_decode($progressinfo['comment']).'</text>';
它将实体转换为普通的HTML,但会打印出原始的html。
<p>This is a test</p>rn<p><strong>this is a test</strong></p>
我希望是这样的:
<p>This is a test</p>rn<p><strong>this is a test</strong></p>
那么,如何将包含HTML实体的字符串转换为要在HTML中呈现的原始HTML呢?
谢谢
发布于 2016-10-03 03:06:58
&lt;
是一个双重编码的元素。使用htmlspecialchars_decode
一次可以将其转换为<
,因为&
被转换为&
。然后,浏览器将其呈现为<
,而不是元素。使用该函数两次,它将呈现为HTML。
echo htmlspecialchars_decode(htmlspecialchars_decode('&lt;p&gt;This is a test&lt;/p&gt;rn&lt;p&gt;&lt;strong&gt;this is a test&lt;/strong&gt;&lt;/p&gt;'));
https://stackoverflow.com/questions/39820487
复制相似问题