note 71431 modified in function.wordwrap by thiago
| From: | thiago@php.net | Date: | Mon, 18 Aug 2008 17:26:19 +0000 |
| Subject: | note 71431 modified in function.wordwrap by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143599@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.
<?php
// 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;
}
?>
--was--
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;
}
http://php.net/manual/en/function.wordwrap.php