求高手,关于网址正提取则 本帖最后由 dz215136304 于 2013-09-10 14:52:56 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 preg_match_all 是提取preg_replace_callback 是替换你function url($url){ return $url[1];//原样返回}如何能看出效果呢? 帮我看下这个正则有点问题,如何修改呢1.当字符串中有www.w3.org或者w3.org之类字符串时原样返回,现在问题是 只匹配到了org造成了结果是“http://www.w3.http://localhost/psh/1999/xhtml”2.字符串中的此正则必须包含"i"参数来不区分大小写,档字符串中包含“loginInfo.js”时 也出错,匹配成了“http://localhost/xxx1rr1dpn/loginhttp://localhost/jogp.js”,正确的应该是“http://localhost/xxx1rr1dpn/loginInfo.js”$con='http://www.w3.org/1999/xhtml,http://www.qq.com/loginInfo.js';$url=preg_replace_callback('/(http:\/\/?[a-zA-Z1-9\.]{2,}\.{1}com|cn|info|tk|org|us)/is', 'url', $con);echo $url; function url($url){ echo $url[1]."<br>";if($url[1]=='http://www.w3.org'||$url[1]=='www.w3.org'||$url[1]=='w3.org'){ return $url[1];}return "http://localhost/".str_replace("http://","",$url[1]);//} 试试$con='http://www.w3.org/1999/xhtml,http://www.qq.com/loginInfo.js'; $url=preg_replace_callback('/http:\/\/[\w.]+(com|cn|info|tk|org|us)/is', 'url', $con);echo $url; function url($url){ echo $url[0]."\n"; if($url[0]=='http://www.w3.org'||$url[0]=='www.w3.org'||$url[0]=='w3.org'){ return $url[0];}return "http://localhost/".str_replace("http://","",$url[0]);// } 咨询php开发windows服务的小问题 如何写个通用的函数加载类,并实例化,同时传递参数? 跪求 ~~~验证码的设计完整版,在线等 急招php程序员【深圳】 关于PHP类读取数据库 数据库中一个日期字段和当天的相差天数?? 花了两个月时间改版的wiki,大家PP php 在web中主要用于那些方面?掌握到什么程度可以找一个普通php程序员的工作? Windows 98下安装Apache(PWS) PHP4MySQLphpMyAdmin的方法 请问有没有办法读取客户端的硬盘呀? mysql表改了编码,语句执行就报错 php popen无法使用
preg_replace_callback 是替换你
function url($url){
return $url[1];//原样返回
}
如何能看出效果呢?
1.当字符串中有www.w3.org或者w3.org之类字符串时原样返回,现在问题是 只匹配到了org造成了结果是“http://www.w3.http://localhost/psh/1999/xhtml”
2.字符串中的此正则必须包含"i"参数来不区分大小写,档字符串中包含“loginInfo.js”时 也出错,匹配成了“http://localhost/xxx1rr1dpn/loginhttp://localhost/jogp.js”,正确的应该是“http://localhost/xxx1rr1dpn/loginInfo.js”$con='http://www.w3.org/1999/xhtml,http://www.qq.com/loginInfo.js';
$url=preg_replace_callback('/(http:\/\/?[a-zA-Z1-9\.]{2,}\.{1}com|cn|info|tk|org|us)/is', 'url', $con);
echo $url;
function url($url){
echo $url[1]."<br>";
if($url[1]=='http://www.w3.org'||$url[1]=='www.w3.org'||$url[1]=='w3.org'){
return $url[1];
}
return "http://localhost/".str_replace("http://","",$url[1]);//
}
$con='http://www.w3.org/1999/xhtml,http://www.qq.com/loginInfo.js';
$url=preg_replace_callback('/http:\/\/[\w.]+(com|cn|info|tk|org|us)/is', 'url', $con);
echo $url;
function url($url){
echo $url[0]."\n";
if($url[0]=='http://www.w3.org'||$url[0]=='www.w3.org'||$url[0]=='w3.org'){
return $url[0];
}
return "http://localhost/".str_replace("http://","",$url[0]);//
}