note 76945 added to function.substr-replace
| From: | joecorcoran at gmail dot com | Date: | Tue, 07 Aug 2007 13:50:59 +0000 |
| Subject: | note 76945 added to function.substr-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129245@lists.php.net to get a copy of this message | ||
I've made a minor amendment to the function in the post below, to strip away the full stop
(period) if the truncation occurs at the exact end of a sentence (the full stop spoils the
ellipsis):
<?php
function truncate($text,$numb) {
$text = html_entity_decode($text, ENT_QUOTES);
if (strlen($text) > $numb) {
$text = substr($text, 0, $numb);
$text = substr($text,0,strrpos($text," "));
//This strips the full stop:
if ((substr($text, -1)) == ".") {
$text = substr($text,0,(strrpos($text,".")));
}
$etc = "...";
$text = $text.$etc;
}
$text = htmlentities($text, ENT_QUOTES);
return $text;
}
//Call function
truncate($text, 75);
----
Server IP: 87.124.64.96
Probable Submitter: 217.206.132.242
----
Manual Page -- http://www.php.net/manual/en/function.substr-replace.php
Edit -- https://master.php.net/note/edit/76945
Del: integrated -- https://master.php.net/note/delete/76945/integrated
Del: useless -- https://master.php.net/note/delete/76945/useless
Del: bad code -- https://master.php.net/note/delete/76945/bad+code
Del: spam -- https://master.php.net/note/delete/76945/spam
Del: non-english -- https://master.php.net/note/delete/76945/non-english
Del: in docs -- https://master.php.net/note/delete/76945/in+docs
Del: other reasons-- https://master.php.net/note/delete/76945
Reject -- https://master.php.net/note/reject/76945
Search -- https://master.php.net/manage/user-notes.php