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.