db->from('sms'); $this->db->where('slug',$slug,TRUE); $template=$this->db->get()->row(); if(!$template) { return FALSE; } $tags_raw=$template->tags; $tags=explode(',',$tags_raw); $template->content=$this->inject_substitute($template->content,$tags,$data); return $template; } public function inject_substitute($raw, $tags, $data) { foreach ($data as $key => $value) { if (in_array($key, $tags)) { $raw = str_replace('{{{' . $key . '}}}', $value, $raw); } } return $raw; } }