使命是取代所有< img>带有< div>的给定字符串中的标签标签和src属性作为内部文本.
在寻找答案时我找到了 similar question
在寻找答案时我找到了 similar question
<?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.
这是PHP的
原文链接:https://www.f2er.com/php/130612.htmlDOMDocument
类擅长的问题:
$dom = new DOMDocument(); $dom->loadHTML($content); foreach ($dom->getElementsByTagName('img') as $img) { // put your replacement code here } $content = $dom->saveHTML();