$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);
php 去掉图片的宽度、高度设置
最新推荐文章于 2021-03-25 13:43:01 发布
本文介绍了一种使用PHP正则表达式去除HTML图片标签中的宽度和高度属性的方法。通过两个preg_replace函数调用,分别移除了width和height属性,从而使图片能够自适应不同的布局需求。
7061





