PHP regular expressions-php Tutorial

Source: Internet
Author: User
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. comc 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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.