替换结构再判断
改为:
width和height的值是变动的,如果width 如果width > 805
那么height = height * 805 /width ;
width= 805
这个正则加判断怎么写啊?最近用到好多正则,怎么样才能把正则学好呢?
------解决方案--------------------
请说明你的规则
../Documents/medies/ESIL_xiaoshengqi1.gif
这个乍来的
Image:ESIL_xiaoshengqi1.gif 这个呢?
width="550" height=" 400" 这个呢???上面有两个,需要哪个?
------解决方案--------------------
参考一下:
$s=<param name="movie" value="/images/1/17/ESIL_xiaoshengqi2.swf"><param name="bgcolor" value="#FFFFFF"><param name="scale" value="exactfit"><embed src="/images/1/17/ESIL_xiaoshengqi2.swf" width="1000" height="400" bgcolor="#FFFFFF" scale="exactfit" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed> html;$r= preg_replace('#.+<embed>]*>.+#s','<img src="../Documents/medies/%242" alt="Image:$2" style="max-width:90%" height="$4" longdesc="/index.php/Image:$2">',$s);preg_match('#width="(\d+)"\s*height="(\d+)"#i',$r,$m);if($m[1]>805){ $h=($m[2]*805)/$m[1] ; $r=preg_replace('/(width=)"(\d+)"(\s*height=)"(\d+)"/s','$1"$2"$3"'.$h.'"',$r);}echo $r;<br><font color="#e78608">------解决方案--------------------</font><br><dl class="code">PHP code<pre class="brush:php;toolbar:false">$s =<param name="movie" value="/images/1/17/ESIL_xiaoshengqi2.swf"><param name="bgcolor" value="#FFFFFF"><param name="scale" value="exactfit"><embed src="/images/1/17/ESIL_xiaoshengqi2.swf" width="1550" style="max-width:90%" bgcolor="#FFFFFF" scale="exactfit" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed> TXT;$r= preg_replace_callback('#.+<embed>]*>.+#s', 'back', $s);function back($r) { if($r[3] > 805) { $r[4] = round($r[4]*805/$r[3]); $r[3] = 805; } return TXT;}echo $r;<div class="clear"> </div></embed>