note 81361 added to function.wordwrap
| From: | znupiDONTWANTSPAM69 at gmail dot comBLAH | Date: | Sun, 24 Feb 2008 16:05:53 +0000 |
| Subject: | note 81361 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136459@lists.php.net to get a copy of this message | ||
If you are dealing with strings that may be very long and without spaces, but at the same time may
be very long WITH spaces and you don't want the ones without spaces ruining your HTML+CSS
layout, here's a function that adds a space (" ") after every $i characters, if no
space is found until that character, so the browser will automatically wrap the text:
<?php
function layout_wrap($str, $i) {
$j = $i;
while ($i < strlen($str)) {
if (strpos($str, ' ', $i-$j+1) > $i+$j || strpos($str, ' ', $i-$j+1) ===
false) {
$str = substr($str, 0, $i) . ' ' . substr($str, $i);
}
$i += $j;
}
return $str;
}
?>
Hope this helps someone :-)
----
Server IP: 69.147.83.197
Probable Submitter: 77.81.204.37
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/81361
Del: integrated -- https://master.php.net/note/delete/81361/integrated
Del: useless -- https://master.php.net/note/delete/81361/useless
Del: bad code -- https://master.php.net/note/delete/81361/bad+code
Del: spam -- https://master.php.net/note/delete/81361/spam
Del: non-english -- https://master.php.net/note/delete/81361/non-english
Del: in docs -- https://master.php.net/note/delete/81361/in+docs
Del: other reasons-- https://master.php.net/note/delete/81361
Reject -- https://master.php.net/note/reject/81361
Search -- https://master.php.net/manage/user-notes.php