在文本中有类似这样的字符串  <img alt="" type="attach" src="attach/xxx/aaa.jpg" />
现在因为fckeditor和前台页面的相对路径不一样,导致这个标签中fckeditor里面显示不出来
在fckeditor里面这样的标签才能正常显示<img alt="" type="attach" src="../../../attach/xxx/aaa.jpg" />type="attach" 这个属性是我用来标识哪些img标签需要转换src属性用的标志,没有其他意义现在想在php里面转换他们 用了如下的正则表达式 可是结果只是把最后一个出现的img标签转换了,前面的没有改变$news['content'] = preg_replace("/(<img.+type=[\"\']attach[\"\'].+src=[\"\'])/i","\$1../../../",$news['content']);请高手们帮帮忙 呵呵

解决方案 »

  1.   

    <?php 
    $str='<img alt="" type="attach" src="attach/xxx/aaa.jpg" />1<img alt="" type="attach" src="attach/xxx/aaa.jpg" />2<img alt="" type="attach" src="attach/xxx/aaa.jpg" />';
    echo $str."<br>";
    $str = preg_replace("/(\<img alt=\"\" type=\"attach\" src=\")/i","<img alt=\"\" type=\"attach\" src=\"../../../",$str); 
    echo $str;
    ?>
    你的需求用str_ireplace就可以解决了吧
      

  2.   

    修正一下。。<?php 
    $str='<img alt="1" type="attach" src="attach/xxx/aaa.jpg" />1<img alt="" type="attach" src="attach/xxx/bbb.jpg" />2<img alt="3" type="attach" src="attach/xxx/ccc.jpg" />sf';
    echo $str."<br>";
    $str = preg_replace("/(\<img.+? type=\"attach\" src=\")/i","\$1../../../",$str); 
    echo $str;
    ?>
      

  3.   

    根据你的又做了一下修改 现在可以了 谢谢楼上的兄弟 $news['content'] = preg_replace("/(\<img.+?type=\"attach\".+?src=\")/i","\$1../../../",$news['content']);