note 26350 deleted from function.wordwrap by aidan
| From: | aidan@php.net | Date: | Wed, 01 Dec 2004 05:32:20 +0000 |
| Subject: | note 26350 deleted from function.wordwrap by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-81210@lists.php.net to get a copy of this message | ||
Note Submitter:
----
pour découper une chaine trop longue (haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa par exemple) :
( en france le mot le plus long fait 25 -> $lng_max = 25)
-------------------------------------
To cut a looooong word
(haaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa for exemple) :
($lng_max = 25 for exemple)
-------------------------------------
function word_wrap($texte,$lng_max) {
// Script
$esp=explode(" ",$texte);
$i=0;
$carac_dep=0;
$tmp_txt="";
// sur tout la longeur du texte
while ($i<=count($esp)) {
$lng_mot=strlen($esp[$i]);
// si le mot est trop gd
if ($lng_mot>$lng_max) {
// on decoupe
$nb_f=($lng_mot/$lng_max)+1;
$mot="";
for ($j=0;$j<=$nb_f;$j++) {
$mot.=substr($esp[$i],($j*$lng_max),$lng_max)." ";
}
$esp[$i]=$mot;
}
$tmp_txt.=$esp[$i]." ";
$i++;
}
return $tmp_txt;
}