从php字符串中删除所有html标记 [英] Remove all html tags from php string

查看:60
本文介绍了从php字符串中删除所有html标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示数据库条目的前110个字符.到目前为止很简单:

I want to display the first 110 characters of a database entry. Pretty easy so far:

<?php echo substr($row_get_Business['business_description'],0,110) . "..."; ?>

但是上面的条目中包含由客户端输入的html代码.因此显示:

But the above entry has html code in it that's been entered by the client. So it displays:

<p class="Body1"><strong><span style="text-decoration: underline;">Ref no:</span></strong> 30001<strong></stro...

显然不好.

我只想剥离所有html代码,因此我需要删除<之间的所有内容.和>从数据库条目中,然后显示前100个字符.

I just want to strip out all html code, so I need to remove everything between < and > from the db entry THEN display the first 100 chars.

有任何想法吗?

推荐答案

使用strip_tags

$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);   //output Test paragraph. Other text

<?php echo substr(strip_tags($row_get_Business['business_description']),0,110) . "..."; ?>

这篇关于从php字符串中删除所有html标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆