note 54249 deleted from function.explode by bjori
| From: | bjori@php.net | Date: | Mon, 25 Sep 2006 08:09:14 +0000 |
| Subject: | note 54249 deleted from function.explode by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117583@lists.php.net to get a copy of this message | ||
Note Submitter: janklopper.at.gmail.dot.com
----
This is a better (altough untested) version of the lastword function, is searches from the end back
to the begin until it finds seperator, and thus only searches the smalest possible part of the
string. very helpfull for large strings.
function lastword($string,$seperator=" ") {//last word of a string
$count=strlen($string);
$count--;
for($i=$count;$i--;$i==0){
if($string[$i]==$seperator){
$location=$i-($i*2);
return substr($string,$location);
}
}
return;
}