Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter word limiter closing html tag

Hello stackoverflow community! I'm using default word limiter in CI. But the trouble is, that it doesnt close html tags and if 1 news ended on strong tag - whole page under this becomes strong. I looked at CI wiki page at github, but if i use that solution, '...' changed place and stay not after limited text, but after not limited h2. html code:

<h2><?=$item['title'];?></h2>           
<?word_limiter($item['text'],25);?>

$item['text'] is in p tags already, because of typing that in crud admin panel. When i used approach from CI wiki page, it looked like this (already on loaded page)

<h2>News</h2> "..."
<p>There is some news i wanna te</p>

I hope anyway would find that question useful aswell. Thanks in advance!

like image 908
Alexander Yakovluk Avatar asked May 03 '26 13:05

Alexander Yakovluk


1 Answers

First, you need to remove HTML tags from the string with strip_tags() function, then you can use word_limiter() helper function safely:

echo word_limiter(strip_tags($item['text']), 25);
like image 194
Hashem Qolami Avatar answered May 05 '26 02:05

Hashem Qolami