I need to truncate some news articles as a summary, about one paragraph 3-4 lines each without cutting the words off. I found this solution but I can't figure out how to implement it into my page.
How to Truncate a string in PHP to the word closest to a certain number of characters?
This is the summary section on the home page where it needs to truncate: News List Summary Screenshot
This is the full article-admin section that the above pulls the news from: Admin News Article Screenshot
Here is the PHP section using mb_substr(ucfirst((strip_tags($news->description, $allowed_tags = '<>'))), 0, 250, "UTF-8") which cuts off the words.
<?php if ($this->wowmodule->getNewsStatus()): ?>
<div class="uk-grid uk-grid-small uk-grid-match uk-child-width-1-1" data-uk-grid>
<?php foreach ($NewsList as $news):?>
<div>
<a href="<?= base_url('news/'.$news->id) ;?>" title="<?= $this->lang->line('button_read_more'); ?>" >
<div class="uk-card uk-card-default news-card uk-card-hover uk-grid-collapse" uk-grid>
<div class="uk-width-1-4@s">
<img src="<?= base_url('assets/images/news/'.$news->image); ?>" alt="<?= $news->title ?>">
</div>
<div class="uk-width-2-3@s uk-card-body">
<h5 class="uk-h5 uk-text-bold uk-margin-small"><?= $news->title ?></h5>
<p class="news-description-text"><?= mb_substr(ucfirst((strip_tags($news->description, $allowed_tags = '<>'))), 0, 250, "UTF-8").' <span style="color:#f8bc51"> <br /><br /><b>Read More...</b></span>'; ?></p>
</div>
</div>
</a>
</div>
<?php endforeach ?>
</div>
<?php endif ?>
Much appreciate any guidance,
Thanks.