I need a function that replace every variable_name inside \'{}\' with the correct variable. Something like this:
$data[\"name\"] = \"Johnny\"; $data[\"age\"
Here you go:
$data["name"] = "Johnny"; $data["age"] = "20"; $string = "Hello my name is {name} and I'm {age} years old."; foreach ($data as $key => $value) { $string = str_replace("{".$key."}", $value, $string); } echo $string;