PHP MySql显示返回的内容而不剥离html标签
我有一个 SQL“文本”数据类型列,里面有 html 标记内的内容,例如
一些内容:
- 一
- 两个
干杯伙计
尼克
I have a column in SQL 'Text' datatype and inside I have content within html tag, eg
somecontent:
- one
- two
... I want the mysql query to echo out the databases contents without stripping the html tags (its possible this is done by php for security reasons or?) so that the html code will render if you get me? At the moment it just lumps out a paragraph which looks aweful! It should be noted security is not much of a concern as this is a project and not going to be exposed publicly
Cheers folks
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
MySQL 不会从文本中去除标签——它不在乎文本是什么。 PHP 也不会删除标签,除非您在代码中的某个位置执行了
strip_tags()
或等效操作。如果你想强制浏览器显示检索到的数据中的标签,可以通过 [
htmlspecialchars()][1]
运行字符串,它会转换 html 元字符 (<、
>
、"
、&
等...)转换为它们的字符实体等效项 (<
、>
等...)。或者您可以通过执行以下操作强制将整个页面呈现为纯文本。
MySQL wouldn't strip tags from text - it couldn't care less what the text is. PHP also wouldn't strip tags, unless somewhere in your code you do a
strip_tags()
or equivalent.If you want to force the browser to display the tags in the retrieved data, you can run the string through [
htmlspecialchars()][1]
, which converts html metacharacters (<
,>
,"
,&
, etc...) to their character entity equivalents (<
,>
, etc...).Or you can force the entire page to be rendered as plain text by doing
除非您明确告知,否则 PHP 不会删除数据库内容。
您确定您的标签在插入之前没有被剥离吗?
或者尝试
stripslashes();
Database content isn't stripped by PHP unless you explicitly tell it to.
Are you sure your tags haven't been stripped before they were inserted?
Alternatively try
stripslashes();
使用 htmlspecialchars_decode() 函数。它对我来说效果很好...
使用指南
您的文本与代码
?>
输出:
关于 Lorem Ipsum 的参考站点,提供有关其起源的信息,以及随机 Lipsum 生成器。
Use htmlspecialchars_decode() function. Its works fine for me...
Use guideline
Your Text with code
?>
Output:
Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.
这对我有用:
例如:
您的浏览器将输出:
我爱你
this works for me:
Ex:
Your browser will output:
I love you
使用以下代码片段:
复制。
Use bellow snippet:
copied.