加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何用PHP从HTML字符串中仅提取文本?

发布时间:2020-12-13 13:23:51 所属栏目:PHP教程 来源:网络整理
导读:我想只从php字符串中提取文本. 这个php字符串包含像标签等的HTML代码. 所以我只需要这个字符串中的简单文本. 这是实际的字符串: div class="devblog-index-content battlelog-wordpress"pstrongThe celebration of the Recon class in our second /stronga
我想只从php字符串中提取文本.

这个php字符串包含像标签等的HTML代码.

所以我只需要这个字符串中的简单文本.

这是实际的字符串:

<div class="devblog-index-content battlelog-wordpress">
<p><strong>The celebration of the Recon class in our second </strong><a href="http://blogs.battlefield.com/2014/10/bf4-class-week-recon/" target="_blank">BF4 Class Week</a><strong> continues with a sneaky stroll down memory lane. Learn more about how the Recon has changed in appearance,name and weaponry over the years&hellip;</strong></p>

<p>&nbsp;</p>

<p style="text-align:center"><a href="http://eaassets-a.akamaihd.net/battlelog/prod/954660ddbe53df808c23a0ba948e7971/en_US/blog/wp-content/uploads/2014/10/bf4-history-of-recon-1.jpg?v=1412871863.37"><img alt="bf4-history-of-recon-1" class="aligncenter" src="http://eaassets-a.akamaihd.net/battlelog/prod/954660ddbe53df808c23a0ba948e7971/en_US/blog/wp-content/uploads/2014/10/bf4-history-of-recon-1.jpg?v=1412871863.37" style="width:619px" /></a></p>

我想从字符串中显示:

The celebration of the Recon class in our second BF4 Class Week continues with a sneaky stroll down memory lane. Learn more about how the Recon has changed in appearance,name and weaponry over the years…

实际上这个文本将放在元描述标签中,所以我不需要元标记中的任何HTML.
我怎么能这样做?关于这种技术的任何想法和想法?

你可以尝试:
echo(strip_tags($your_string));

更多信息:http://php.net/manual/en/function.strip-tags.php

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读