note 27931 deleted from function.substr by aidan
| From: | aidan@php.net | Date: | Sat, 03 Jul 2004 07:52:30 +0000 |
| Subject: | note 27931 deleted from function.substr by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72378@lists.php.net to get a copy of this message | ||
Note Submitter: joaobett@oninet.pt
----
The code below is an alternative to the basename() function in PHP, and it is here to illustrate the
use of the substr() function.
/********************************************
Getting the file name from an address
like http://www.xpto12345.xyz/abc/def/ghi.php
using substr() function
********************************************/
// This procedure only works when the filename
// is at the end of the string
$fn="abc/def/ghi/jkl.php"; // 'where is the filename' string
$a = strlen("$fn");
while ($a>0){
if(substr(substr($fn, $a, strlen($fn)), 0, 1)=="/"){break;}
$b=substr($fn, $a, strlen($fn));
$a=$a-1;
}
print $b;