note 80643 deleted from function.wordwrap by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 18:28:57 +0000 |
| Subject: | note 80643 deleted from function.wordwrap by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155121@lists.php.net to get a copy of this message | ||
Note Submitter: darkimmortal at dkimmortal dot com
----
This function will provide word-wrap functionality to Firefox (most other browsers have a CSS
alternative) by using a zero-width character between every character of any word that goes past the
limited size.
<?php
/**
* @desc Wraps a string using a zero-width character between each character of any word past the size
limit.
* @param string String to wrap
* @param int Word length limit
*
* @return string Cut string
*/
function cut_word($txt, $where=12) {
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]="​";
}
}
return implode("", $d);
}
?>