Copy link to clipboard
Copied
I have a PHP that has within it a series of server side include PHP files.
In each of these files I would like to echo the filename (less .php).
I have tried using:
<?php echo basename($_SERVER['PHP_SELF']) ; ?>
But this only displays the name of the file ENCLOSING all of the Server Side include files.
Is there another simple script I can use?
Thanks
<?php echo basename(__FILE__, '.php'); ?>
Copy link to clipboard
Copied
<?php echo basename(__FILE__, '.php'); ?>
Copy link to clipboard
Copied
BRILLIANT !
WORKS A TREAT THANK YOU!
C
Copy link to clipboard
Copied
BRILLIANT !!!!
YOU ARE A STAR!
C
Colin Walton
WaltonCreative
Copy link to clipboard
Copied
I guess the next questions is HOW does it work...?
Can you possibly talk me through the different parts of the script to explain it please?
Also - I need to combine it with this if script:
<?php if ($urlenlarged == "WA2537") { // Show if URL matches product ?>
So your script replaces WA2537.
In effect I want to do this:
<?php if ($urlenlarged == "<?php echo basename(__FILE__, '.php'); ?>") { // Show if URL matches product ?>
But I know this isn't right as you can't put PHP inside PHP.
Thanks again for all your help!
Colin
Copy link to clipboard
Copied
Don't worry about the second question, I have done this which appears to work ok:
<?php if ($urlenlarged == basename(__FILE__, '.php')) { // Show if URL matches product ?>
I would still like to know what the various parts of your solution do though, if you can spare a few moments please?
<?php echo basename(__FILE__, '.php'); ?>
Copy link to clipboard
Copied
__FILE__ is a PHP constant that gets the full path of the current file. Unlike $_SERVER['PHP_SELF'], it refers to the actual file. As you have discovered, $_SERVER['PHP_SELF'] refers to the current page (in other words, the parent page of any includes).
To see how basename() works, look it up in the PHP manual.
Copy link to clipboard
Copied
Thanks - will do some more reading!
C
Colin Walton
WaltonCreative