My Example:
$name = "Simon";
$string = "My name is [name].";
echo preg_replace("/\[(.*)]/", ${"$1"}, $string);
// Expected: My name is Simon.
// I get: My name is .
// ${"$1"} should be $name?
exit();
When I do only:
echo preg_replace("/\[(.*)]/", "$1", $string);
// I get: My name is name.
// $1 = name
What am i doing wrong? Why is PHP not using the generated $name var? This is only a example. I would like to work this with any replace:
[foo] --> $foo
[bar] --> $bar
...