Created
April 23, 2019 06:47
-
-
Save NimzyMaina/8f8d23e13063fee8cfd2fc8fea317be9 to your computer and use it in GitHub Desktop.
Bulk SMS Templating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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