PHP regular expressions have two links. you want to convert one of them into another HTMLcode, for example, link A: user.qzone.qq.com [color # FF0000] 1340477530 [color] #! App2 & amp; pos [color # FF0000] 1300412602 [color] link B: B. qzone. qq. c PHP regular expression problem
There are two links to convert one to another.
HTML code
For example, link A: http://user.qzone.qq.com/?color=#ff=#1340477530#/color=#! App = 2 & pos = [color = # FF0000] 1300412602 [/color] link 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
How can I change the red part of link A to the red part of link B. Thank you ~~
------ Solution --------------------
Should both uin and blogid be numerical values? Or your 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;}