楼主还是要说一下你要做什么吧 ,就你给的目前的这个字符串,估计是很难做处理,基本上可以说不能实现
<?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);
?>
<?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);
?>
帮帮忙了
写的正则在工具里都能匹配
就是放到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');
?>