I have problem understanding this one:
<?php
$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1}1,$3';
echo preg_replace($pattern, $replacement, $string);
?>
Output is April1,2003. I don’t understand this expression: $replacement = '${1}1,$3';
Would appreciate if somebody clarifies it for me.
Programmer had to use this, because
would act weird and wrong. Also, they couldn’t use
too,because it would cause it to be parsed as the first example.
That’s why there are these brackets, they work as a delimiter between the variable and number
1.It’s the same as
above example will output “Hello Martinand welcome”
but this one
is mistchmashing the variable name with plain text, which is in your replacement, number
1