note 71431 added to function.wordwrap
| From: | tylernt at gmail dot com | Date: | Tue, 28 Nov 2006 19:39:13 +0000 |
| Subject: | note 71431 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120132@lists.php.net to get a copy of this message | ||
I wrote this to keep long strings from making my tables wider than the browser window. To lessen the
impact on performance, only call this function on strings longer than 'X' characters.
// This function will insert the 'wbr' (optional linebreak) tag
// to wrap words in $string longer than 10 characters,
// but will not break inside HTML tags
function mywordwrap($string)
{
$length = strlen($string);
for ($i=0; $i<=$length; $i=$i+1)
{
$char = substr($string, $i, 1);
if ($char == "<")
$skip=1;
elseif ($char == ">")
$skip=0;
elseif ($char == " ")
$wrap=0;
if ($skip==0)
$wrap=$wrap+1;
$returnvar = $returnvar . $char;
if ($wrap>9) // alter this number to set the maximum word length
{
$returnvar = $returnvar . "<wbr>";
$wrap=0;
}
}
return $returnvar;
}
----
Server IP: 216.194.113.175
Probable Submitter: 15.235.137.71
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/71431
Del: integrated -- https://master.php.net/note/delete/71431/integrated
Del: useless -- https://master.php.net/note/delete/71431/useless
Del: bad code -- https://master.php.net/note/delete/71431/bad+code
Del: spam -- https://master.php.net/note/delete/71431/spam
Del: non-english -- https://master.php.net/note/delete/71431/non-english
Del: in docs -- https://master.php.net/note/delete/71431/in+docs
Del: other reasons-- https://master.php.net/note/delete/71431
Reject -- https://master.php.net/note/reject/71431
Search -- https://master.php.net/manage/user-notes.php