Alexander Yakovluk
Alexander Yakovluk

Reputation: 79

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!

Upvotes: 3

Views: 2574

Answers (1)

Hashem Qolami
Hashem Qolami

Reputation: 99484

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);

Upvotes: 6

Related Questions