Ask the value inside the regular ${1} How to use function processing? How to make a notation

Source: Internet
Author: User
What is the value of ${1} in the regular function processing? How do you spell it?
$user _pattern = "/\@ (. +?) ([\s|:]|$)/";
$str = Preg_replace ($user _pattern, ' ${1} ', $str);

How to ${1} in Chinese UrlEncode function transcoding? I do not use the following as a string.

$str = Preg_replace ($user _pattern, ' ${1} ', $str);


------Solution--------------------
With Preg_replace_callback (),
Such as:

Function CB ($matches) {
Return sprintf ('%1 $ S ', UrlEncode ($matches [1]));
}
$user _pattern = "/\@ (. +?) ([\s
------Solution--------------------
:]
------Solution--------------------
$)/";
$str = ' jacky@yyq.cn ';
$str = Preg_replace_callback ($user _pattern, ' CB ', $STR);
Echo $str;
------Solution--------------------
See Preg_replace_callback 5th parameter, set to 1 to replace only once, and the first replacement is a tag in the
------Solution--------------------
This post was last edited by xuzuning on 2013-04-10 09:53:52

Your original plan is doable, just missing something.
$user _pattern = "/\@ (. +?) ([\s
------Solution--------------------
:]
------Solution--------------------
$)/E ";
$str = Preg_replace ($user _pattern, ' ${1} ', $str);

You can tell by comparing it with what you wrote.
  • 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.