日期:2014-05-17  浏览次数:20465 次

求正则达人
IE浏览器下:
<img style="width: 1024px; height: 806px;" alt="" src="/upload/articles/20121204/images/201212040328205506018siw5.jpg" complete="complete" data-cke-saved-src="/upload/articles/20121204/images/201212040328205506018siw5.jpg"/>

FF浏览器下:
<img style="width: 1024px; height: 806px;" src="/upload/articles/20121204/images/201212040328205506018siw5.jpg" complete="complete" data-cke-saved-src="/upload/articles/20121204/images/201212040328205506018siw5.jpg" alt="" />

这个是用编辑器上传的图片,现在我需要把图片里面的style全部删除掉,后面的内容保持原样。求高手帮我写个正则!!
------解决方案--------------------

$str='<img style="width: 1024px; height: 806px;" src="/upload/articles/20121204/images/201212040328205506018siw5.jpg" complete="complete" data-cke-saved-src="/upload/articles/20121204/images/201212040328205506018siw5.jpg" alt="" />';
$aa=preg_replace('/style=".*?"\s+/','',$str);
echo $aa;

------解决方案--------------------
$str='<img style="width: 1024px; height: 806px;" alt="" src="/upload/articles/20121204/images/201212040328205506018siw5.jpg" complete="complete" data-cke-saved-src="/upload/articles/20121204/images/201212040328205506018siw5.jpg"/>';

echo preg_replace('/(<img\s+[^>]*)style\s*=\s*"[^"]*"/i', '$1', $str);
------解决方案--------------------
#1注意:只过滤<img内的style,你那样,如果外面有style代码也被过滤掉了。