Heim >Backend-Entwicklung >PHP-Tutorial > 正则去除图片width和height部分。该怎么解决
正则去除图片width和height部分。
有许多图片,有的有width和height,有的没有width和height。
如何使用正则去除所有图片的width和height部分?我的代码无效,求助。
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <pre class="brush:php;toolbar:false"> <?php $s = '<img hspace="4" vspace="4" border="1" alt="Nagoya Institute folding X-Frame car lacks S-foils, hyperdrive, rolls on a big orange ball" src="http://www.blogcdn.com/www.engadget.com/media/2010/09/x-frame-2010-09-02-600.jpg" /> <img src="http://media02.hongkiat.com/speed-performance-check/pingdom.jpg" alt="Pingdom" border="0" title="18 Website Speed and Performance Checking Tools"> <img style="max-width:90%" height="100px" src="http://blog.makezine.com/upload/2010/09/vice_grip_with_more_cowbell/expand-o.jpg" alt="expand-o.jpg">'; $img=preg_replace('/ width="\d+" height="\d+"/', '', $s); echo $img; ?>
<div class="clear"> </div>