note 42689 added to function.strrpos
| From: | harlequinATgmxDOTde at rn2 dot php dot net | Date: | Wed, 26 May 2004 13:59:31 +0000 |
| Subject: | note 42689 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70117@lists.php.net to get a copy of this message | ||
Made a mistake in my previous note:
the total length must be greater than the the last occurence, otherwise there's no filename
behind the trailing slash:
So once again, this is my function for finding a filename in a URL:
function getfname($url){
$pos = strrpos($url, "/");
if ($pos === false) {
// not found / no filename in url...
return false;
} else {
// Get the string length
$len = strlen($url);
if ($len < $pos){
print "$len / $pos";
// the last slash we found belongs to http:// or it is the
trailing slash of a URL
return false;
} else {
$filename = substr($url, $pos+1, $len-$pos-1);
}
}
return $filename;
}
----
Manual Page -- http://www.php.net/manual/en/function.strrpos.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42689
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42689&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42689&report=yes
Search -- http://master.php.net/manage/user-notes.php