Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

echo filename of ssi files

Participant ,
Feb 25, 2010 Feb 25, 2010

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

TOPICS
Server side applications

Views

1.0K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 27, 2010 Feb 27, 2010

<?php echo basename(__FILE__, '.php'); ?>

Votes

Translate
LEGEND ,
Feb 27, 2010 Feb 27, 2010

Copy link to clipboard

Copied

<?php echo basename(__FILE__, '.php'); ?>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 27, 2010 Feb 27, 2010

Copy link to clipboard

Copied

BRILLIANT !

WORKS A TREAT THANK YOU!

C

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 27, 2010 Feb 27, 2010

Copy link to clipboard

Copied

BRILLIANT !!!!

YOU ARE A STAR!

C

Colin Walton

WaltonCreative

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 27, 2010 Feb 27, 2010

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 27, 2010 Feb 27, 2010

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'); ?>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 27, 2010 Feb 27, 2010

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 28, 2010 Feb 28, 2010

Copy link to clipboard

Copied

LATEST

Thanks - will do some more reading!

C

Colin Walton

WaltonCreative

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines