楼主还是要说一下你要做什么吧 ,就你给的目前的这个字符串,估计是很难做处理,基本上可以说不能实现
<?php 
$str = 'dfsafdhttp://www.sina.com/aa.phpdsgfdsgfds www.qq.com  fdsfsd http://www.qq.com.cn/htmlgfdsf天于qq.com';
function test($text){ 
echo preg_replace('(http://|ftp://|www\.?|)(([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?){0,1}','',$text); 

test($str); 
?> 

解决方案 »

  1.   

    我就是想把文本中的所有链接给过滤掉
    帮帮忙了
    写的正则在工具里都能匹配
    就是放到php方法里就不行了
    不晓得是怎么回事
      

  2.   

    php里正则要用//包含,里面出现/全部需要转义。试试
    <?php 
    function test($text) 

    echo preg_replace('/(http:\/\/|ftp:\/\/|www\.?|)(([\w-]+\.)+[\w-]+(\/[\w-.\/?%&=]*)?){0,1}/','',$text); 

    test('dfsafdhttp://www.sina.com/aa.phpdsgfdsgfds www.qq.com  fdsfsd http://www.qq.com.cn/htmlgfdsf天于qq.com'); 
    ?>