is there a way to parse a string like eval does? For example this code using eval
[php.net example]
Example 1. eval() example - simple text merge
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "\n";
eval ("\$str = \"$str\";");
echo $str. "\n";
?>
The above example will show:
This is a $string with my $name in it.
This is a cup with my coffee in it.
[/php.net example]
instead I would like to use my own function like
Example 2.
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "\n";
echo string_parser($str) . "\n";
?>
The above example will show:
This is a $string with my $name in it.
This is a cup with my coffee in it.
?
Thanks for your time
- Me