当前位置:企业首页 >> 新闻中心

分享到: 更多

php 正则表达式替换与正则替换函数

发布时间:2010-08-30 08:10 点击量:

php教程 正则表达式替换与正则替换函数
/*
下面我们是要把指定正则出来的内空替换成别一种内容,这样做我们就会要用到正则替换函数preg_replace了,下面的实例是


文本有下面标签

<img style src="<?=$url?>/images/styleno.jpg" width="30" height="30" />
<img style src="<?=$url?>/images/styleno.jpg" width="30" height="30" />
<img src="images/styleno.jpg" width="30" height="30" />
<img src="images/styleno.jpg" width="30" height="30" />
想用正则把他们替换成
有 style的 替换成<img src="<?=$url?>/images/styleno.jpg" width="30" height="30" />
没style 的 替换成<img src="<?=$path?>/images/styleno.jpg" width="30" height="30" />

*/

$content1 ='<img style src="<?=$url?>/images/styleno.jpg" width="30" height="30" />';
$content ='<img style src="/images/styleno.jpg" width="30" height="30" />';
$a='<img src="<?=$url?>/images/styleno.jpg" width="30" height="30" />';
echo preg_replace('/<imgs+styles+src=['"]?[^'"]*['"]?\s+.*\/>/i',$a,$content);

$content1 ='<img src="images/styleno.jpg" width="30" height="30" />';
$b='<img src="<?=$path?>/images/styleno.jpg" width="30" height="30" />';
echo preg_replace('/<img src=['"]?[^'"]*['"]?\s+.*\/>/i',$b,$content1);

(责任编辑:admin)

上一篇:ip地址的正则表达式


下一篇:没有了

北京php培训

php家教

案例展示图

网  址:

www.chinaitweb.com

客服热线:13391795197[可发短信注明来意]

客服热线:13717978877[可发短信注明来意]

qq:802041000