错误preg_replace删除所有div内部内容

时间:2018-10-03 14:18:56

标签: php regex preg-replace

$content = '<div class="block_thumb_slide_show"><img alt="smartphone" class="aligncenter size-full">Test abc<p> <strong>Màn hình 3D</strong></p></div>';
$content = preg_replace('#<div.*?>(.*?)</div>#i', '<p>\1</p>', $content);
echo $content;

结果无法将div替换为p。如何解决

<p><img alt="smartphone" class="aligncenter size-full">Test abc<p> <strong>Màn hình 3D</strong></p></p>

1 个答案:

答案 0 :(得分:0)

如果要将div替换为p,为什么不尝试使用:

myval.update