PHP正则有关问题

WBOY
Release: 2016-06-13 13:34:06
Original
809 people have browsed it

PHP正则问题
有两个链接,想将其中一个转换成另一个

HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
比如:
链接A : http://user.qzone.qq.com/[color=#FF0000]1340477530[/color]#!app=2&pos=[color=#FF0000]1300412602[/color]
链接B :http://b.qzone.qq.com/cgi-bin/blognew/blog_output_data?uin=[color=#FF0000]xxxxx[/color]&blogid=[color=#FF0000]yyyyyyy[/color]&numperpage=1000&property=GoRE

Copy after login

想将链接A的红色的部分换成链接B红色对应的部分,怎么弄啊。谢谢~~

------解决方案--------------------
uin 和 blogid 原来都应该是数值吧? 还是你的xxxx yyyy?
PHP code

$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;
} <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template