Reputation: 86
I am currently developing a CMS and want to add in the functionality of limiting an excerpt of text by its line length. Say I want to control the display of text and ensure all blocks are the same height by controlling the amount of lines of text that show.I am using for each to display inbox function message data. In the message section it shows full message and I want to limit it into 30
<?php
if(isset($records)) :
foreach($records as $row) :
?>
<tr >
<td class="right"><?php echo $row->contactus_name; ?></td>
<td class="right"><?php echo $row->contactus_email; ?></td>
<td class="right"><?php echo $row->contactus_phone; ?></td>
<td class="right tertiary-text-secondary text-justify"><?php echo $row->contactus_comment; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot></tfoot>
</table>
<?php else : ?>
<p>No records</p>
<?php endif; ?>
Upvotes: 1
Views: 1843
Reputation: 15609
If you include the text
helper in your controller:
$this->load->helper('text');
or in autoload.php
:
$autoload['helper'] = array('url', 'form', 'html', 'text');
You can then use word_limiter()
.
From the documentation:
$string = "Here is a nice text string consisting of eleven words.";
$string = word_limiter($string, 4);
// Returns: Here is a nice…
There is also character_limiter()
which works the same way. Again, from the documentation:
$string = "Here is a nice text string consisting of eleven words.";
$string = character_limiter($string, 20);
// Returns: Here is a nice text string…
Upvotes: 3
Reputation: 3702
//IN CONTROLLER
$this->load->helper('text');
<?php echo word_limiter($row->contactus_comment,30); ?>
Upvotes: 1