脚本宝典收集整理的这篇文章主要介绍了PHP – 替换标签并返回src,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP $content = "this is something wITh an <img src=\"test.png\"/> in it."; $content = PReg_replace("/<img[^>]+\>/i","(image) ",$content); echo $content; ?>
结果:
this is something with an (image) in it.
问题:如何升级脚本蚂蚁得到这个结果:
this is something with an <div>test.png</div> in it.
DOMDocument
类擅长的问题:
$dom = new DOMDocument(); $dom->loadhtml($content); foreach ($dom->getelementsbytagname('img') as $img) { // put your replacement code here } $content = $dom->savehtml();
以上是脚本宝典为你收集整理的PHP – 替换标签并返回src全部内容,希望文章能够帮你解决PHP – 替换标签并返回src所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。