Skip to content

Instantly share code, notes, and snippets.

@TakesTheBiscuit
Created March 1, 2018 16:04
Show Gist options
  • Save TakesTheBiscuit/f48a7a2f85f70aedf18c066c2fcabf97 to your computer and use it in GitHub Desktop.
Save TakesTheBiscuit/f48a7a2f85f70aedf18c066c2fcabf97 to your computer and use it in GitHub Desktop.
string replacement
<?php
$stringage = [
'order_id'=>'5678',
'name'=>'NO ONE cares'
];
echo replace_with_personal_data('There was a problem on order #[order_id] please phone [name]', $stringage);
function replace_with_personal_data($string, $strings) {
$output = $string;
foreach ($strings as $injectable_key => $injectable_string) {
$output = str_replace('['.$injectable_key.']', $injectable_string, $output);
}
return $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment