Skip to content

Instantly share code, notes, and snippets.

@NimzyMaina
Created April 23, 2019 06:47
Show Gist options
  • Save NimzyMaina/8f8d23e13063fee8cfd2fc8fea317be9 to your computer and use it in GitHub Desktop.
Save NimzyMaina/8f8d23e13063fee8cfd2fc8fea317be9 to your computer and use it in GitHub Desktop.
Bulk SMS Templating
<?php
$sms = "Dear {{name}}, {{amount}} has been deposited to your bank account. Your current balance is {{balance}}. Thank you for banking with us.";
$required = ['{{name}}','{{amount}}','{{balance}}'];
$values = [
$required[0] => 'John Doe',
$required[1] => 'KES 5,000',
$required[2] => 'KES 75,000'
];
$sms = str_replace('}}','}} ', $sms);
$is_valid = (count($required) == count(array_intersect(explode(' ', strtolower($sms)), $required)));
if($is_valid){
echo strtr($sms, $values);
}
else{
echo "Unable to parse template";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment