改为:
width和height的值是变动的,如果width 如果width > 805
那么height = height * 805 /width ;
width= 805
这个正则加判断怎么写啊?最近用到好多正则,怎么样才能把正则学好呢?
------解决方案--------------------
请说明你的规则
../documents/medies/esil_xiaoshengqi1.gif
这个乍来的
image:esil_xiaoshengqi1.gif 这个呢?
width=550 height= 400 这个呢???上面有两个,需要哪个?
------解决方案--------------------
参考一下:
php code$s=html;$r= preg_replace('#.+]*>.+#s','',$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;
------解决方案--------------------
php code$s =txt;$r= preg_replace_callback('#.+]*>.+#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;
