Skip to content

Instantly share code, notes, and snippets.

@westonwatson
Created November 27, 2012 15:15
Show Gist options
  • Save westonwatson/4154746 to your computer and use it in GitHub Desktop.
Save westonwatson/4154746 to your computer and use it in GitHub Desktop.
Replace BB Style Tags using Data from Objects and Arrays
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