[英]PHP: How to convert ASCII to HTML or how to decode string
I have a database table (SQL Server 2008) with a table that contains some ASCII-encoded characters (formatted as nvarchar(max)
). 我有一个数据库表(SQL Server 2008),其中的表包含一些ASCII编码的字符(格式为
nvarchar(max)
)。
Usually the browser converts these automatically to HTML but I use a jQuery plugin that cannot read these and requires the content in HTML. 通常,浏览器会自动将这些内容转换为HTML,但我使用的jQuery插件无法读取这些内容,并且需要HTML内容。 I am passing my content to this plugin using PHP.
我正在使用PHP将内容传递给此插件。
Is there a way in PHP to convert such strings manually to HTML ? PHP中是否有一种方法可以将此类字符串手动转换为HTML?
Example - db content: 示例-数据库内容:
<p>Some sample text with <strong>HTML</strong></p>
Example - required output for plugin: 示例-插件所需的输出:
<p>Some sample text with <strong>HTML</strong></p>
I tried finding a solution myself but it seems there are different approaches available and I wasn't sure about the correct one here. 我尝试自己寻找解决方案,但似乎有不同的方法可用,我不确定这里是否正确。
您可以尝试html_entity_decode();
html_entity_decode('string', ENT_QUOTES, 'UTF-8');
用这个,
echo html_entity_decode($string, ENT_COMPAT, 'UTF-8');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.