note 92879 added to function.wordwrap
| From: | sbm007 at gmail dot com | Date: | Wed, 12 Aug 2009 21:55:16 +0000 |
| Subject: | note 92879 added to function.wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159413@lists.php.net to get a copy of this message | ||
I modified the wordwrap function submitted by "tylernt at gmail dot com"' to suit my
needs.
This is what I came up with:
<?php
function BreakWord($Message, $Length)
{
$ReturnMessage = "";
$CurrentLength = 0;
$Length = strlen($Message);
for ($i = 0; $i < $Length; $i++)
{
$CurrentCharacter = substr($Message, $i, 1);
if ($CurrentCharacter == " ")
$CurrentLength = 0;
else
$CurrentLength++;
$ReturnMessage = $ReturnMessage . $CurrentCharacter;
if ($CurrentLength > $Length)
{
$ReturnMessage = $ReturnMessage . "​";
$CurrentLength = 0;
}
}
return $ReturnMessage;
}
?>
This is a bit different to wordwrap. Allow me to explain:
If a word exceeds length $Length, it will insert a zero-width space character at that point. This
will cause browsers to wrap the text onto the next line (exactly the same as the CSS3 property:
word-wrap: break-word;)
Usage is simple:
BreakWord($Message, $Length)
$Message is your text/string
$Length is maximum length before a word is wrapped onto next the next line. $Length should generally
speaking be the amount of capital double-u's (W) can fit on one line of your page. (Or inside a
table/div/etc)
Hope this helps, please do not hesitate to contact me if you have a problem.
----
Server IP: 64.71.164.2
Probable Submitter: 91.105.223.78
----
Manual Page -- http://www.php.net/manual/en/function.wordwrap.php
Edit -- https://master.php.net/note/edit/92879
Del: integrated -- https://master.php.net/note/delete/92879/integrated
Del: useless -- https://master.php.net/note/delete/92879/useless
Del: bad code -- https://master.php.net/note/delete/92879/bad+code
Del: spam -- https://master.php.net/note/delete/92879/spam
Del: non-english -- https://master.php.net/note/delete/92879/non-english
Del: in docs -- https://master.php.net/note/delete/92879/in+docs
Del: other reasons-- https://master.php.net/note/delete/92879
Reject -- https://master.php.net/note/reject/92879
Search -- https://master.php.net/manage/user-notes.php