What is the value of ${1} in the regular function processing? How do you spell it?

Source: Internet
Author: User
$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);


Reply to discussion (solution)

With Preg_replace_callback (),
Such as:

Function CB ($matches) {
Return sprintf ('%1 $ S ', UrlEncode ($matches [1]));
}
$user _pattern = "/\@ (. +?) ([\s|:]|$)/";
$str = ' jacky@yyq.cn ';
$str = Preg_replace_callback ($user _pattern, ' CB ', $STR);
Echo $str;

With Preg_replace_callback (),
Such as:

Function CB ($matches) {
Return sprintf ('%1 $ S ', UrlEncode ($matches [1]));
}
$user _pattern = "/\@ (. +?) (......

As if, but the two values are all turned, I just change one, that is, click on the link inside, the link display text does not change, such as only change the regular value of this http://127.0.0.1/${1}, the other does not change.

See Preg_replace_callback 5th parameter, set to 1 to replace only once, and the first replacement is a tag in the

Reference to the 1 floor Varkychan reply: With Preg_replace_callback () bar,
Such as:

Function CB ($matches) {
Return sprintf ('%1 $ S ', UrlEncode ($matches [1]));
}
$user ...

Very simple, modify the parameters in the sprintf,
Such as:
Function CB ($matches) {
Return sprintf ('%s ', UrlEncode ($matches [1]), $matches [1]);
}

Your original plan is doable, just missing something.

$user _pattern = "/\@ (. +?) ([\s|:]|$)/E ";  $str = Preg_replace ($user _pattern, ' ${1} ', $str);

You can tell by comparing it with what you wrote.

This post was last edited by xuzuning on 2013-04-10 09:53:52
Your original plan is doable, just missing something.
PHP Code?12$user_pattern = "/\@ (. +?) ([\s|:]|$)/E "; $str = Preg_replace ($user _pattern, ' "
Starting with php5.5, the/E modifier starts discarding, and it is recommended to use Preg_replace_callback ()

This post was last edited by xuzuning on 2013-04-10 09:53:52
Your original plan is doable, just missing something.
PHP Code?12$user_pattern = "/\@ (. +?) ([\s|:]|$)/E "; $str = Preg_replace ($user _pattern, ' "
As if not, or as a character. There's no link.

I don't need to fool you!

$str = ' @ Chinese aa: '; $user _pattern = "/\@ (. +?) ([\s|:]|$)/E ";  $str = Preg_replace ($user _pattern, ' ${1} ', $str); Echo $str;
Chinese AA

Reference 2 floor Billssjone reply: Reference 1 floor Varkychan reply: With Preg_replace_callback () bar,
Such as:

Function CB ($matches) {
Return sprintf ('%1 $ S ', UrlEncode ($m ...

It doesn't seem to be good.

Function CB ($matches) {    return sprintf (' a href= "http://127.0.0.1/%1$s" >%1$s ', UrlEncode ($matches [1]), $ Matches[1]);} $STR = "Test @ My Weibo add link"; $user _pattern = "/\@ (. +?) ([\s|:]|$)/"; $str = Preg_replace_callback ($user _pattern, ' CB ', $STR); Echo $str;


I deliberately removed the link <符号,看看直接输出效果,还是两个值都会变,输出是:
<符号,看看直接输出效果,还是两个值都会变,输出是:>
Test a href= "Http://127.0.0.1/%E6%88%91%E7%9A%84%E5%BE%AE%E5%8D%9A" >%e6%88%91%e7%9a%84%e5%be%ae%e5%8d%9a add link

#9 code should be written

Function CB ($matches) {    return sprintf (' a href= "http://127.0.0.1/%s" >%s ', UrlEncode ($matches [1]), $matches [1] );} $STR = "Test @ My Weibo add link"; $user _pattern = "/\@ (. +?) ([\s|:]|$)/"; $str = Preg_replace_callback ($user _pattern, ' CB ', $STR); Echo $str;
Test a href= "http://127.0.0.1/%CE%D2%B5%C4%CE%A2%B2%A9" > My Weibo Add link

I don't need to fool you! PHP code?1234$str = ' @ Chinese aa: '; $user _pattern = "/\@ (. +?) ([\s|:]|$)/E "; $str = Preg_replace ($user _pattern, ' ${1} ', $str ...

Oh, thank you, this can, just now I test your code is not correct, that is, did not add that e, so the result of the test is the direct output:
A href=\ "HTTP://127.0.0.1/". UrlEncode ("Chinese AA"). " \ "> Chinese AA

#9 code should be written in PHP code?1234567function CB ($matches) {return sprintf (' a href= "http://127.0.0.1/%s" >%s ', UrlEncode ($ Matches[1]), $matches [1]);} $STR = "Test @ My Weibo add link"; $user _pattern = "/\@ (...)

Thank you so much, it's finally done, and I've been testing from yesterday to today.

  • Related Article

    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.