Skip to content

Instantly share code, notes, and snippets.

Avatar

James Nodws Nodws

View GitHub Profile
View Truncate text by word.php
<?php
function texto($text, $limit=8) {
$text = strip_tags($text);
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
}
return $text;
}