I need to replace some text in a string. I think an example can explain better:
[myFile.json]
{ "Dear":"newString1", "an example string":"newString2" }
[example.php]
$myString = "@Dear@ name, this is @an example string@.";
function gimmeNewVal($myVal){
$obj = json_decode(file_get_contents('myFile.json'));
return $obj->$myVal;
}
echo gimmeNewVal("Dear"); // This print "newString1"
So, what I need is to find any strings between the '@' symbol and for each string found I need to replace using the gimmeNewVal() function.
I already tried with preg_* functions but I'm not very able with regex...
Thanks for your help