有两个链接,想将其中一个转换成另一个比如:
链接A : http://user.qzone.qq.com/1340477530#!app=2&pos=1300412602
链接B :http://b.qzone.qq.com/cgi-bin/blognew/blog_output_data?uin=xxxxx&blogid=yyyyyyy&numperpage=1000&property=GoRE想将链接A的红色的部分换成链接B红色对应的部分,怎么弄啊。谢谢~~ 

解决方案 »

  1.   

    A : http://user.qzone.qq.com/1340477530#!app=2&pos=1300412602
    B : http://b.qzone.qq.com/cgi-bin/blognew/blog_output_data?uin=xxxx&blogid=yyyy&numperpage=1000&property=GoRE
    晕。发颜色失效了。
    将链接A的两个数字:1340477530   1300412602
    换成链接B的:xxxxx ,yyyyy
      

  2.   

    <?php
    $url_1='http://user.qzone.qq.com/1340477530#!app=2&pos=1300412602';
    $url_2='http://b.qzone.qq.com/cgi-bin/blognew/blog_output_data?uin=xxxx&blogid=yyyy&numperpage=1000&property=GoRE';$query=parse_url($url_2);
    parse_str($query['query'],$a);
    $patterns=array('/(com\/)\d+/','/(pos=)\d+/');echo preg_replace($patterns,array('$1'.$a['uin'],'$1'.$a['blogid']),$url_1);这样??
      

  3.   

    谢谢,
    但是好像反了,目标是:把url_1中的数据换到url_2的数据内
    $url_2='http://b.qzone.qq.com/cgi-bin/blognew/blog_output_data?uin=1340477530&blogid=1300412602&numperpage=1000&property=GoRE';
      

  4.   

    uin 和 blogid 原来都应该是数值吧? 还是你的xxxx yyyy?$str1 = "http://user.qzone.qq.com/1340477530#!app=2&pos=1300412602";
    $str2 = "http://b.qzone.qq.com/cgi-bin/blognew/blog_output_data?uin=1111&blogid=2222&numperpage=1000&";
    preg_match('/([\d]+).*pos=([\d]+)$/', $str1, $match);
    if (isset($match[1]) && isset($match[2])) {
        $pa=array('/uin=[\d]+/','/blogid=[\d]+/');
        $re=array('uin='.$match[1],'blogid='.$match[2]);
        $str2=preg_replace($pa,$re,$str2);
        echo $str2;
    }
      

  5.   

    ?
    就是 xxxx yyyy?
    $str1 = "http://user.qzone.qq.com/1340477530#!app=2&pos=1300412602";
    $str2 = "http://b.qzone.qq.com/cgi-bin/blognew/blog_output_data?uin=xxxx&blogid=yyyy&numperpage=1000&";
    preg_match('/([\d]+).*pos=([\d]+)$/', $str1, $match);
    if (isset($match[1]) && isset($match[2])) {
        $pa=array('/[x]{4}/','/[y]{4}/');
        $re=array($match[1],$match[2]);
        $str2=preg_replace($pa,$re,$str2);
        echo $str2;
    }
      

  6.   

    是数字,已经OK了。。谢谢版主还有一个小问题,如果想匹配 $str1 = "http://user.qzone.qq.com/1340477530#!app=2&pos=1300412602";
    中包含qzone.qq.com(是否有QQ空间)是用正则匹配好,还是用strstr好啊。preg_match('/qzone.qq.com/',$str1,$match);
    print_r($match);
      

  7.   

    strpos()检测一个字符串是否在另一个字符串中。
      

  8.   

    本帖最后由 PhpNewnew 于 2012-04-26 18:46:50 编辑