[英]How to get text without html tags
I have a Database table to save news. 我有一个数据库表来保存新闻。 the news field type is TEXT (I save the news with its styles inline).
新闻字段类型为TEXT(我以内联样式保存新闻)。 Now when I show the news on the site it shows with all the styles and that is great but my problem is: I want to make last 10 news table on mainpage will show the title and PART OF NEWS i use a php code to get some letters from my returned news value from the database:
现在,当我在网站上显示新闻时,它会以所有样式显示,这很好,但是我的问题是:我要在主页上显示最后10个新闻表,以显示标题和部分新闻,我使用php代码来获取一些信息来自数据库的我返回的新闻值中的字母:
$str1 = $cat_news[$i]['news'];
$str1 = wordwrap($str1, 100);
$str1 = explode("\n", $str1);
when I echo the $str[1]; 当我回显$ str [1]时; it shows me the styles like this:
它向我展示了这样的样式:
letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none;
I want to show the text without any style just some letters from the text followed by ... 我想显示没有任何样式的文本,仅显示文本中的一些字母,然后显示...
There is a function in PHP called strip_tags
. PHP中有一个名为
strip_tags
的函数。 You can use it like this: 您可以像这样使用它:
$str1 = $cat_news[$i]['news'];
$str1 = strip_tags($str1);
$str1 = wordwrap($str1, 100);
$str1 = explode("\n", $str1);
This should get rid of all HTML formatting. 这应该摆脱所有HTML格式。
您可以使用strip_tags() ,但是请注意,如果HTML格式不正确等,它可以删除的内容比您想的要多。它不能对格式等进行适当的检查。也可以使用DOMDocument ,但这确实取决于文本和格式的正确性和完整性如何。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.