php 正则替换img src
我这里写了个,你们运行下看看:$str='<center><imgsrc="/ueditor/php/upload/image/20180118/151625019276...
我这里写了个,你们运行下看看:
$str = '<center><img src="/ueditor/php/upload/image/20180118/1516250192768590.jpg" title="1516250192768590" alt="20160822181735.jpg"></center>';
$str=preg_replace('/<img.+(src="?)\/ueditor\/(.+\.(jpg|gif|bmp|bnp|png)\"?)>/i',"/upload/ueditor/\${2}",$str);
echo $str;
======怎样去掉:title和alr ====
目前问题就是, 这2个属性干不掉:title="1516250192768590" alt="20160822181735.jpg" 展开
$str = '<center><img src="/ueditor/php/upload/image/20180118/1516250192768590.jpg" title="1516250192768590" alt="20160822181735.jpg"></center>';
$str=preg_replace('/<img.+(src="?)\/ueditor\/(.+\.(jpg|gif|bmp|bnp|png)\"?)>/i',"/upload/ueditor/\${2}",$str);
echo $str;
======怎样去掉:title和alr ====
目前问题就是, 这2个属性干不掉:title="1516250192768590" alt="20160822181735.jpg" 展开
1个回答
展开全部
应该这样就可以了:
$str = '<center><img src="/ueditor/php/upload/image/20180118/1516250192768590.jpg" title="1516250192768590" alt="20160822181735.jpg"></center>';
$str=preg_replace("/<img.+(src=\"?)\/ueditor\/(.+\.(jpg|gif|bmp|bnp|png)?)(\".*?title.*?alt.*?)\>/i","<img src=\"/upload/ueditor/\${2}\">",$str);
echo $str;
这样得到的HTML代码为:
<center><img src="/upload/ueditor/php/upload/image/20180118/1516250192768590.jpg"></center>
这应该是你想要的结果哦
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |