Created
November 27, 2012 15:15
-
-
Save westonwatson/4154746 to your computer and use it in GitHub Desktop.
Replace BB Style Tags using Data from Objects and Arrays
This file contains hidden or 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
static function replace_tags($full_text,$data_objects_array){ | |
//using key => value pairs replace tag_names with object_sttributes | |
/* Example Object | |
* | |
* $object["user"] = $user; | |
* $object["dealer"] = $dealership; | |
* $awesome_text = replace_tags($tagged_text,$object); | |
*/ | |
foreach ($data_objects_array as $object_name => $data_object){ | |
if (is_object($data_object)) foreach(get_object_vars($data_object) as $key => $value){ | |
$full_text = str_ireplace("[".$object_name."_".$key."]", $value, $full_text); | |
} | |
if ($is_array($data_object)) foreach($data_object as $key => $value){ | |
$full_text = str_ireplace("[".$key."]", $value, $full_text); | |
} | |
} | |
return $full_text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment