I would like to append html to an item in my array before echoing it on my page and am unsure how to go about doing it.
My data is put into an array like so:
$query = $this->db->get();
foreach ($query->result() as $row) {
$data = array(
'seo_title' => $row->seo_title,
'seo_description' => $row->seo_description,
'seo_keywords' => $row->seo_keywords,
'category' => $row->category,
'title' => $row->title,
'intro' => $row->intro,
'content' => $row->content,
'tags' => $row->tags
);
}
return $data;
I would like to perform the following on my 'tags' before returning the data to my view:
$all_tags = explode( ',' , $row->tags );
foreach ( $all_tags as $one_tag ){
echo '<a href="/search/'. $one_tag .'">' . $one_tag . '</a>';
The reason for doing this is that the tags in my database contain no html and are simply separated by commas like so news,latest,sports
and I want to convert them into
<a href="/search/sports">sports</a> ...
My reason for doing this here rather than when I echo the data is that I don't want to repeat myself on every page.