How can I use the function to process the value $ {1} in the regular expression? How to write it? $ User_pattern & nbsp ;=& nbsp; "/& nbsp ;\@ (. + ?) ([\ S |:] | $ & nbsp;)/"; & nbsp; $ str & nbsp ;=& nbsp; preg _ How do I use the function to process the value $ {1} in the regular expression? How to write it?
$ User_pattern = "/\ @ (. + ?) ([\ S |:] | $ )/";
$ Str = preg_replace ($ user_pattern, '$ {1}', $ str );
How can I transcode the URL function of $ {1} in Chinese? I can't do this using the following code. it's all strings.
$ Str = preg_replace ($ user_pattern, '$ {1}', $ str );
------ Solution --------------------
Use preg_replace_callback,
For example:
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 --------------------
For more information, see the preg_replace_callback 5th parameters. if it is set to 1, it is replaced only once.
------ Solution --------------------
This post was finally edited by xuzuning at 09:53:52. it is feasible to edit your original scheme, but some things are missing.
$ User_pattern = "/\ @ (. + ?) ([\ S
------ Solution --------------------
:]
------ Solution --------------------
$)/E ";
$ Str = preg_replace ($ user_pattern, '"$ {1}"', $ str );
Compare it with what you wrote.