让这段正则:$str= preg_replace("/<img.*?src=\"(.+?)\".*?>/","<img src=\"\\1\" width='300' height='inherit'/>", $str);
输出后变成:<p><img width="300" height="inherit"></p>
自己尝试修改,发现无效:$str= preg_replace("/<img.*?src=\"(.+?)\".*?>/","<p><img src=\"\\1\" width='300' height='inherit'/><\/p>", $str);
帮我看下,正则怎样给匹配的img添加p标签?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
志秀宇成 2021-11-07 21:06关注$str = '<img src="http://php.p2hp.com/images/logos/php-logo.svg">'; $str = preg_replace("/<img.*?src=\"(.+?)\".*?>/", "<p><img src=\"\\1\" width=\"300\" height=\"inherit\"/></p>", $str); exit($str);本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报