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

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了如何用PHP从HTML字符串中仅提取文本?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想只从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&amp;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

脚本宝典总结

以上是脚本宝典为你收集整理的如何用PHP从HTML字符串中仅提取文本?全部内容,希望文章能够帮你解决如何用PHP从HTML字符串中仅提取文本?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。