note 88840 added to function.strlen
| From: | n dot rijksen at gmail dot com | Date: | Tue, 10 Feb 2009 15:21:55 +0000 |
| Subject: | note 88840 added to function.strlen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150451@lists.php.net to get a copy of this message | ||
Small notice on "kyle dot florence ~at~ gmail dot com" his function.
The way his function is now the substr would be performed on a html string and THEN convert
it's html entities.. whilst it should convert the html entities before performing the substr in
order to get the expected results..
The correct code would be;
<?php
// Trim a string to specified length and append an end character (default = ...)
function str_trim($str, $lim = 32, $chr = '…')
{
// If length of string is less than $lim, return string
if (strlen($str = htmlentities($str)) <= $lim) return $str;
// Else, cut string down to size
return substr(htmlentities($str), 0, $lim - 3).$chr;
}
?>
----
Server IP: 66.207.199.35
Probable Submitter: 216.113.38.178
----
Manual Page -- http://www.php.net/manual/en/function.strlen.php
Edit -- https://master.php.net/note/edit/88840
Del: integrated -- https://master.php.net/note/delete/88840/integrated
Del: useless -- https://master.php.net/note/delete/88840/useless
Del: bad code -- https://master.php.net/note/delete/88840/bad+code
Del: spam -- https://master.php.net/note/delete/88840/spam
Del: non-english -- https://master.php.net/note/delete/88840/non-english
Del: in docs -- https://master.php.net/note/delete/88840/in+docs
Del: other reasons-- https://master.php.net/note/delete/88840
Reject -- https://master.php.net/note/reject/88840
Search -- https://master.php.net/manage/user-notes.php