note 82778 modified in function.wordwrap by thiago
| From: | thiago@php.net | Date: | Mon, 18 Aug 2008 17:23:30 +0000 |
| Subject: | note 82778 modified in function.wordwrap by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143593@lists.php.net to get a copy of this message | ||
I wanted something that would word wrap just one word. People were doing ffffffffffffffffff in my
comments page on my site, annoyingly stretching the page. but I didn't want to wrap at a
certain fixed length, just wanted to break up words like that only. Here's what I came up with
if anyone wants it.
<?php
function one_wordwrap($string,$width){
$s=explode(" ", $string);
foreach ($s as $k=>$v) {
$cnt=strlen($v);
if($cnt>$width) $v=wordwrap($v, $width, "<br />", true);
$new_string.="$v ";
}
return $new_string;
}
?>
--was--
I wanted something that would word wrap just one word. People were doing ffffffffffffffffff in my
comments page on my site, annoyingly stretching the page. but I didn't want to wrap at a
certain fixed length, just wanted to break up words like that only. Here's what I came up with
if anyone wants it.
function one_wordwrap($string,$width){
$s=explode(" ", $string);
foreach ($s as $k=>$v) {
$cnt=strlen($v);
if($cnt>$width) $v=wordwrap($v, $width, "<br />", true);
$new_string.="$v ";
}
return $new_string;
}
http://php.net/manual/en/function.wordwrap.php