I need to truncate string and rewrite it back to array
I have got a function where I get data from data base
$data['about_text_list'] = $this->about_text_model->get_array();
I get these fields from data base : id, num, header, text, language
I need to strip_tags and truncate text with function word_limiter
foreach ($data['about_text_list'] as $items)
{
$data['about_text_list']['text'] = word_limiter($items['text'], 100);
$data['about_text_list']['text'] = strip_tags($items['text']);
}
in view I do foreach
<? foreach ($about_text_list as $line) : ?>
<td><?=$line['text']?></td>
<? endforeach; ?>
But I get error, please tell me how to do correct things like this…
In the loop in your controller, you’re limiting the word count, then setting that to the value in the array. Then, you’re overwriting that value with the
strip_tagsfunction. You’re using both functions on the same value instead of using the altered values. (And I would strip the tags first, then limit the word count.)You’re also just overwriting the
$data['about_text_list']['text']value each iteration. I’m assuming this needs to be an array of ‘text’ values? I would create a new array with the updated content and merge your$data['about_text_list']array with the new array.Change that loop to this:
Also, I’m not sure what your error is (as you haven’t told us), but make sure you’re loading the text helper to give you access to the
word_limiterfunction:Of course, this all depends on the structure of your array, which I’m guessing at right now.