21,893
社区成员




$str="ahahttp://www.chinindfaasdl.comahahttp://www.chinindfaasdl.com
hahahahttp://www.chinindfaasdl.com嗲话地哦862189375829http://www.chinindfaasdl.comhiaohdgioas
862189375829http://www.chinindfaasdl.comhiaohdgioas
撒旦法经理卡数据的分类http://www.chinindfaasdwfdfsdl.com";
echo preg_replace('#http://[\w\.-]+\.(com|net|org|hk|info|cc|edu)#s', '<a href="$0">$0</a>', $str);
$reg = '/(http:\/\/.*\.com)/isU';
<?php
$str = "http://dfhakoadghttp://daidgjiadpugidua";
$reg = '#http://(?:\w(?!http://))+(?:\w(?=http://))?#'; // 其中\w的规则可以改成定义的规则
$matches = array();
preg_match_all($reg, $str, $mathces);
print_r($mathces);
//只要保证你的url含有http开头的话,可以不使用正则:
$s = 'http://dfhakoadghttp://daidgjiadpugidua';
$a = explode('http://', $s);
foreach($a as $r) {
if($r) echo "http://$r", '<br/>';
}
//http://dfhakoadg
//http://daidgjiadpugidua
<?php
$str="ahahttp://www.chinindfaasdl.comahahttp://www.chinindfaasdl.com
hahahahttp://www.chinindfaasdl.com嗲话地哦862189375829http://www.chinindfaasdl.comhiaohdgioas
862189375829http://www.chinindfaasdl.comhiaohdgioas
撒旦法经理卡数据的分类http://www.chinindfaasdwfdfsdl.com";
$str = preg_replace('/(http:\/\/.*?\.com)/', '<a href="\1">click</a>', $str);
var_dump($str);
不知道你要换哪里? 我加了个click