本帖最后由 dz215136304 于 2013-09-10 14:52:56 编辑

解决方案 »

  1.   

    preg_match_all 是提取
    preg_replace_callback 是替换你
    function url($url){
      return $url[1];//原样返回
    }
    如何能看出效果呢?
      

  2.   

    帮我看下这个正则有点问题,如何修改呢
    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]);//
    }
      

  3.   

    试试
    $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]);// 
    }