note 26350 added to function.wordwrap
| From: | php-general at lists dot php dot net | Date: | Sun, 27 Oct 2002 18:52:54 +0000 |
| Subject: | note 26350 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38625@lists.php.net to get a copy of this message | ||
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;
}
--
http://www.php.net/manual/en/function.wordwrap.php
http://master.php.net/manage/user-notes.php?action=edit+26350
http://master.php.net/manage/user-notes.php?action=delete+26350
http://master.php.net/manage/user-notes.php?action=reject+26350