简体   繁体   English

从基于文本的内容中删除某些html标签

[英]Remove certain html tags from text based content

I'm using CKE text editor http://ckeditor.com on my web site. 我在我的网站上使用CKE文本编辑器http://ckeditor.com

When user create content using this text editor, text may have paragraphs, bullet lists, headers with different sizes etc... and all content is stored in mysql database as HTML format...So, when text is displayed from database, let say on home page as a featured article, it is displayed in same form as user stored it to db, so it causes aesthetics problems I want to know the best way to remove html tags from text string with PHP or Javacript and leave just text, because I dont wanna manualy type all possible html tags with str_replace() function. 当用户使用此文本编辑器创建内容时,文本可能具有不同大小的段落,项目符号列表,标题等...并且所有内容都以HT​​ML格式存储在mysql数据库中...因此,当从数据库中显示文本时,可以说在首页上作为特色文章,它的显示形式与用户将其存储到db的形式相同,因此它会引起美学问题,我想知道使用PHP或Javacript从文本字符串中删除html标签并仅保留文本的最佳方法,因为我不想使用str_replace()函数手动键入所有可能的html标签。 Thanks in advance 提前致谢

You're after PHP's strip_tags function. 您正在使用PHP的strip_tags函数。 This removes both HTML and PHP tags from a string. 这将从字符串中删除HTML和PHP标记。 Reference page: http://php.net/manual/en/function.strip-tags.php 参考页面: http//php.net/manual/en/function.strip-tags.php

Example: 例:

$text = "<p>My string</p>";
echo strip_tags($text); //This would print "My string"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM