Zend - The PHP Company




Files and Directories

Add Code


Find File Name  

Type: code fragment
Added by: jay_chack
Entered: 17/09/2000
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 6366
This generalized code snippet finds out the current file name without the extension part and can be of use in any template driven site where you have to dynamically generate names of graphics or other files to be loaded depending on the name of the page loading. Being generalised it doesnt matter how comlicated the URL is or how deep the current file is embedded. It still pulls out the name correctly.


<?

/* 

This generalized code snippet finds out the current file name without the extension part and can be of use in any template driven site where you have to dynamically generate names of graphics or other files to be loaded depending on the name of the page loading. All you have to do is use a uniform naming procedure for those files including the page name. Being generalised it doesnt matter how comlicated the URL is or how deep the current file is embedded. It still pulls out the name correctly.

This can be used as an include file or even as a function with minor changes.

Use variable $page in your program to build names of graphics or other files to be loaded for the current page.

*/ 

$page getenv(SCRIPT_NAME);
$page split("/"$page);
$n count($page)-1;
$page $page[$n];
$page split("."$page2);
$page $page[0]";

?>


Usage Example


<IMG SRC="<? echo "$page-banner.gif"?>" WIDTH=599 HEIGHT=60 BORDER=0 ALT="">


Rate This Script





Search



This Category All Categories