I think I have made a bad mistake…
It’s the input:
http://www.example.com/do.php?action=5&say=text
http://www.example.com/do.php?action=8&say=text
http://www.example.com/do.php?action=10&say=text
I want to put another parameter after action:
preg_replace('/action=[0-9]/', 'action=$1¶m=test', $text);
but its output is:
http://www.example.com/do.php?action=¶m=test&say=text
http://www.example.com/do.php?action=¶m=test&say=text
http://www.example.com/do.php?action=¶m=test&say=text
as you see, the action values have removed.
Where’s my mistake?
The
$1is a substring match, and starts with the first parenthesis. So to use it would be/actions=([0-9]+)/to capture the digits.