php – 如何从HTML中的所有标签之间获取数组中的文本?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 如何从HTML中的所有标签之间获取数组中的文本?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在所有< span>之间的数组中获取文本. < /跨度>标签HTML,我尝试过这个代码,但它只返回一个事件:
PReg_match('/<span>(.+?)<\/span>/is',$row['tbl_highlighted_icon_content'],$matches);

echo $matches[1];

我的HTML

<span>The wish to</span> be unfairly treated is a compromise attempt that would COMBINE attack <span>and innocen</span>ce.  Who can combine the wholly incompatible,and make a Unity  of what can NEVER j<span>oin? Walk </span>you the gentle way,

我的代码仅返回一次span标签,但是我想要以html格式PHP数组的形式获取每个span标签中的所有文本.

您需要切换到 preg_match_all功能

$row['tbl_highlighted_icon_content'] = '<span>The wish to</span> be unfairly treated is a compromise attempt that would COMBINE attack <span>and innocen</span>ce. Who can combine the wholly incompatible,and make a unITy of what can NEVER j<span>oin? Walk </span>you the gentle way,';    

preg_match_all('/<span>.*?<\/span>/is',$matches);

var_dump($matches);

正如你可以看到的,数组是正确填充的,所以你可以回应所有的匹配

脚本宝典总结

以上是脚本宝典为你收集整理的php – 如何从HTML中的所有标签之间获取数组中的文本?全部内容,希望文章能够帮你解决php – 如何从HTML中的所有标签之间获取数组中的文本?所遇到的问题。

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

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