你少了个斜杠
$text = preg_replace('!<img[^>]+src=(\'|")(.*)(\\1).*>!siU', '', $text);

解决方案 »

  1.   

    怎么不行?好好的啊<?php$text = "<img src='avc.gif' alt='' />";
    $text = preg_replace('!<img[^>]+src=(\'|")(.*)(\\1).*>!siU', '
      

  2.   

    <?php$text = "<img src='avc.gif' alt='' />ggergesdfv'<img src='avcfsdfsd.gif' alt='' />";
    $text = preg_replace('!<img[^>]+src=([\'|"])([^\'"]+)(\\1)(.*)>!isU', '', $text);
    echo $text?>
    不知道是不是你要的效果
      

  3.   

    如果直接像你这样写就可以. 但我用所见所得编辑器post过去的就是不行,奇怪了? 它输出来的明明就是<img src=""啊....
      

  4.   

    我如果先把它转为安全代码的话就不行了.
    $text = str_replace('<','&lt;',$text);
    $text = str_replace('>','&gt;',$text);
    $text = preg_replace('#<img[^>]+src=(\'|")(.*)(\\1).*>#siU', '', $text);
      

  5.   

    1、给出你post得到的数据。
    2、可改用能直接产生ubb代码的在线编辑器
      

  6.   

    post过去后引号都转了,你post后清除一下数据,
    $text = $_POST["text"];
    $text = stripslashes($text);....然后再做replace
      

  7.   

    深空说的没错,加个stripslashes($text)后再用preg_replace后就成功了.
      

  8.   

    真是的, post过去引号会自动加\?
      

  9.   

    手册里看看这个部分就明白了:magic_quotes_gpc boolean
    Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically. 注: If the magic_quotes_sybase directive is also ON it will completely override magic_quotes_gpc. Having both directives enabled means only single quotes are escaped as ''. Double quotes, backslashes and NUL's will remain untouched and unescaped. See also get_magic_quotes_gpc() 
      

  10.   

    再问大侠一个问题由于一般的<img转 ', $text);
    echo $text?>它找到this.width>时就认为结束了....请问如何解决这个问题呢? 大侠如能回答,我会另开贴给分的...
      

  11.   

    运行以上代码会得出:screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'Click here to open new window,www.ydy.com\';}" border=0 pop="www.ydy.com">
      

  12.   

    主要是因为非贪婪匹配只是找出最近的">",而恰巧你的JS脚本中使用了它。
    如果你的img标签最后跟的都是">或'>的话可以加上这个来判断到达标签末尾.
    正则如下
    '#<img[^>]+src=(\'|")(.*)(\\1).*("|\')>#siU'
      

  13.   

    这个可不一定哦... 像 <img src="" border=0> 就不是以'>结尾的, 这个不是由我们的程序控制的..