note 72682 added to function.strrpos
| From: | ChristOff at osu1 dot php dot net | Date: | Mon, 29 Jan 2007 18:50:18 +0000 |
| Subject: | note 72682 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122327@lists.php.net to get a copy of this message | ||
Function to truncate a string
Removing dot and comma
Adding ... only if a is character found
function TruncateString($phrase, $longueurMax = 150) {
$phrase = substr(trim($phrase), 0, $longueurMax);
$pos = strrpos($phrase, " ");
$phrase = substr($phrase, 0, $pos);
if ((substr($phrase,-1,1) == ",") or (substr($phrase,-1,1) == ".")) {
$phrase = substr($phrase,0,-1);
}
if ($pos === false) {
$phrase = $phrase;
}
else {
$phrase = $phrase . "...";
}
return $phrase;
}
----
Server IP: 194.246.101.61
Probable Submitter: 82.250.0.8
----
Manual Page -- http://www.php.net/manual/en/function.strrpos.php
Edit -- https://master.php.net/note/edit/72682
Del: integrated -- https://master.php.net/note/delete/72682/integrated
Del: useless -- https://master.php.net/note/delete/72682/useless
Del: bad code -- https://master.php.net/note/delete/72682/bad+code
Del: spam -- https://master.php.net/note/delete/72682/spam
Del: non-english -- https://master.php.net/note/delete/72682/non-english
Del: in docs -- https://master.php.net/note/delete/72682/in+docs
Del: other reasons-- https://master.php.net/note/delete/72682
Reject -- https://master.php.net/note/reject/72682
Search -- https://master.php.net/manage/user-notes.php