Last active
December 14, 2015 07:09
-
-
Save Stichoza/5048086 to your computer and use it in GitHub Desktop.
Easily replace variable-like tags in string using associative array's keys and values.
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 | |
# usage: $array = array("name" => "Stichoza", "website" => "stichoza.com"); | |
# echo replace_identifiers("Visit {{name}}'s website at {{website}}", $array); | |
function replace_identifiers($string, $assoc_array) { | |
foreach ($assoc_array as $key => $value) { | |
$string = str_replace("{{".$key."}}", $value, $string); | |
} | |
return $string; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment