php 去掉图片的宽度、高度设置

$str = '<img width="748" height="123" src="xxx" />';

//去掉图片宽度
$a1 = '/(<img.*?)width=(["\'])?.*?(?(2)\2/\s)([^>]+>)/is';
$str = preg_replace($a1,'$1$3',$str);

//去掉图片高度
$a2 = '/(<img.*?)height=(["\'])?.*?(?(2)\2/\s)([^>]+>)/is';
$str = preg_replace($a2,'$1$3',$str);

猜你喜欢

转载自blog.csdn.net/cuilei210/article/details/78783940