【发布时间】:2018-10-03 14:18:55
【问题描述】:
$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>
【问题讨论】:
-
使用
preg_replace("/(</?)div/", "$1p", $content) -
预期回报是多少?
标签: php regex preg-replace