The replacement value of preg_replace has a subexpression value plus a value, as shown in the following 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?
Reply to discussion (solution)
$aa=preg_replace('/^(a)123(b)$/ie','"$1".$ih."$2"',$aa);
Preg_replace ('/^ (a) * (B) $/I', '$ 1'. $ ih.' $ 2', $ aa );
$ih=500;$aa='a123b';$aa=preg_replace('/^(a)123(b)$/i','${1}'.$ih.'${2}',$aa);print_r($aa);
'$1'.$ih.'$2'
Equivalent
'$1'.‘100’.'$2'$1100$2
Modify rule '$ 1'. $ ih.' $2'
What is actually passed to preg_replace is '$1100 $2'
Therefore, ambiguity occurs between $1 and $11.
So we need to distinguish it manually '$ {1} 100 $2'
Your format is '$ {1}'. $ ih. '$2'
Note: double quotation marks are not allowed.
They all answered well, but unfortunately they didn't score much. I knew I had come here early and had been depressed for a whole day.