note 60750 deleted from function.wordwrap by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 18:32:23 +0000 |
| Subject: | note 60750 deleted from function.wordwrap by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155134@lists.php.net to get a copy of this message | ||
Note Submitter: Anthony Catel (paraboul at gmail . com)
----
<?php
function cut_word($txt, $where) {
if (empty($txt)) return false;
for ($c = 0, $a = 0, $g = 0; $c<strlen($txt); $c++) {
$d[$c+$g]=$txt[$c];
if ($txt[$c]!=" ") $a++;
else if ($txt[$c]==" ") $a = 0;
if ($a==$where) {
$g++;
$d[$c+$g]="<br />";
$a = 0;
}
}
return implode("", $d);
}
?>
Wrap word for cut only long word :
<?
cut_word($sentence, 25);
?>