note 27931 modified in function.substr by jmcastagnetto

From: Date: Thu, 26 Dec 2002 06:23:14 +0000
Subject: note 27931 modified in function.substr by jmcastagnetto
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-41295@lists.php.net to get a copy of this message
[Editor's note: for a more flexible and simpler solution, use basename()] /******************************************** 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; --was-- /******************************************** 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; http://www.php.net/manual/en/function.substr.php

« previous php.notes (#41295) next »