couper

Couper une chaine sans couper les mots

Ça va couper chérie !

php couper mot, couper mot php, couper chaine php, php couper chaine, php couper string, couper string php, php substr mot, php tronquer mot, php couper une chaine un mot, tronquer mot php, substr sans couper mot, substr mot, php substr mot entier, php substr mots, substr mots php

Cette fonction coupe la chaîne $string à la longueur $length si nécessaire sans couper le dernier mot et y ajoute la chaine $cutString si il y a eu une troncature.


function cleanCut($string,$length,$cutString = '...')
{
if(strlen($string) <= $length)
{
return $string;
}
$str = substr($string,0,$length-strlen($cutString)+1);
return substr($str,0,strrpos($str,' ')).$cutString;
}

Image : limbte

 
 

b1n@sp1n