Skip to content

Instantly share code, notes, and snippets.

@kuroisuna
Created May 13, 2016 19:07
Show Gist options
  • Save kuroisuna/887c9ad7210ce3e1726042dd1808ccf2 to your computer and use it in GitHub Desktop.
Save kuroisuna/887c9ad7210ce3e1726042dd1808ccf2 to your computer and use it in GitHub Desktop.
<?php
$text = 'Hola soy {name} y mi edad es {age}';
$vars = [
'name' => 'Daniel',
'age' => 16,
];
foreach ($vars as $varKey => $varValue) {
$pattern = "/{{$varKey}}/";
$text = preg_replace($pattern, $varValue, $text);
}
echo $text;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment