Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ellipsis($text, $max = 140, $append = '…') {
- if(strlen($text) <= $max) return $text; // Si la chaine est trop petite, on ne fait rien
- $out = substr($text, 0, $max); // On coupe la chaine à $max
- if(strpos($out, ' ') === FALSE) return $out . $append; // S'il n'y a pas d'espace dans la chaine coupée, on la retourne
- return preg_replace('/\w+$/', '', $out) . $append; // On enleve ce qu'il y a après le dernier espace de la chaine coupée
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement