note 70517 added to function.substr
| From: | digitallydesigneddotcodotuk at osu1 dot php dot net | Date: | Thu, 19 Oct 2006 13:27:21 +0000 |
| Subject: | note 70517 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118751@lists.php.net to get a copy of this message | ||
If you use substr to only get a part of a string it can cut off letters in the middle of a word...
This is my function to stop this.
<?
function fnShortenText($pstrText, $plintLength)
{
$larrSplitText = split(" ", $pstrText);
$i = 0;
$lstrMakeNewText = "";
do
{
if(strlen($lstrMakeNewText) + strlen($larrSplitText[$i]) < $plintLength)
{
$lstrMakeNewText .= $larrSplitText[$i];
$lstrMakeNewText .= " ";
$i++;
}
else
{
$lstrMakeNewText .= "...";
$i = count($larrSplitText);
}
}
while($i < count($larrSplitText));
return $lstrMakeNewText;
}
?>
----
Server IP: 85.116.0.130
Probable Submitter: 62.252.0.5 (proxied: 86.16.144.140)
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/70517
Del: integrated -- https://master.php.net/note/delete/70517/integrated
Del: useless -- https://master.php.net/note/delete/70517/useless
Del: bad code -- https://master.php.net/note/delete/70517/bad+code
Del: spam -- https://master.php.net/note/delete/70517/spam
Del: non-english -- https://master.php.net/note/delete/70517/non-english
Del: in docs -- https://master.php.net/note/delete/70517/in+docs
Del: other reasons-- https://master.php.net/note/delete/70517
Reject -- https://master.php.net/note/reject/70517
Search -- https://master.php.net/manage/user-notes.php