note 81361 deleted from function.wordwrap by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 18:28:27 +0000 |
| Subject: | note 81361 deleted from function.wordwrap by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155120@lists.php.net to get a copy of this message | ||
Note Submitter: znupiDONTWANTSPAM69 at gmail dot comBLAH
----
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 :-)