使命是将给定字符串中所有的<img>
标签替换为<div>
标签,并将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.