The preg_replace value has a subexpression value plus a value.

Source: Internet
Author: User
Preg_replace the replacement value has a subexpression value plus a numerical value. this post is finally edited by panlvfei from 2014-04-0215:3. The following is a simple replacement: $ ih100; $ aaa123b; $ aapreg_replace (^ () 123 (B) $ I, $1. $ ih. $2, $ aa); the replacement value of pri preg_replace has a subexpression value plus a value.

This post was last edited by panlvfei at 15:31:02

The following is a simple replacement:
$ Ih = 100;
$ Aa = 'a123b ';
$ Aa = preg_replace ('/^ (a) 123 (B) $/I', '$ 1'. $ ih.' $ 2', $ aa );
Print_r ($ aa );
The result is incorrect. if $ ih is changed to a letter, the first and $1 digits will be lost. Adding a letter at $1 is normal. isn't it my computer problem?
------ Solution --------------------
$ Aa = preg_replace ('/^ (a) 123 (B) $/ie',' "$1". $ ih. "$2" ', $ aa );

------ Solution --------------------

$ Ih = 500;
$ Aa = 'a123b ';
$ Aa = preg_replace ('/^ (a) 123 (B) $/I', '$ {1 }'. $ ih. '$ {2}', $ aa );
Print_r ($ aa );

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.