Skip to content

Instantly share code, notes, and snippets.

@arif98741
Created March 19, 2023 13:30
Show Gist options
  • Save arif98741/d25828cfde8e0d84d64d0a0fc3637448 to your computer and use it in GitHub Desktop.
Save arif98741/d25828cfde8e0d84d64d0a0fc3637448 to your computer and use it in GitHub Desktop.
Curly Brace Sms Template PHP
$template = "I am {{name}}, and I work for {{company}}. I am {{age}} years old.";
# Your template tags + replacements
$replacements = array(
'name' => 'Jeffrey',
'company' => 'Microsoft Inc Pvt Ltd.',
'age' => 27
);
function bind_to_template($replacements, $template) {
return preg_replace_callback('/{{(.+?)}}/',
static function($matches) use ($replacements) {
return $replacements[$matches[1]];
}, $template);
}
// I am Jeffrey, and I work for Envato. I am 27.
echo bind_to_template($replacements, $template);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment