Maison  >  Article  >  développement back-end  >  正则去除图片width和height部分。该怎么解决

正则去除图片width和height部分。该怎么解决

WBOY
WBOYoriginal
2016-06-13 13:45:21917parcourir

正则去除图片width和height部分。
有许多图片,有的有width和height,有的没有width和height。

如何使用正则去除所有图片的width和height部分?我的代码无效,求助。

PHP code
<!--

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;
?> 


------解决方案--------------------
PHP code
 <div class="clear">
                 
              
              
        
            </div>
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn