Forum Moderators: coopster

Message Too Old, No Replies

Current script(file) name

Current script(file) name

         

photocroatia

11:40 pm on Dec 8, 2004 (gmt 0)

10+ Year Member



I have just realized the power of php and am rewriting most of my site in php making it dynamic as possible.

The question I have is this:

I have a script called aa.php, bb.php, cc.php so on...

The content I am storing in files called aa-detail.php, bb-detail.php, cc-detail.php so on ...

I there a way of getting the current file name and then adding "-detail" in between the file prefix and file suffix.

If this is possible then I could make the calling of the detail script dynamic rather than hard coding.

Thank you.


jatar_k

12:41 am on Dec 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the following was not tested in any way

$whoami = split('/',$_SERVER['PHP_SELF']);
$pagename = $whoami[count($whoami)-1];
$whoami = split('\.',$pagename);
$pagename = $whoami[0];
$pagename = $pagename . '-detail.php';
echo '<p>',$pagename;

jatar_k

12:48 am on Dec 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



actually i tested it now and that first one works but so does this

$whoami = split('/',$_SERVER['PHP_SELF']);
$pagename = $whoami[count($whoami)-1];
$pagename = str_replace('.','-detail.',$pagename);
echo '<p>',$pagename;

2 lines less ;)

photocroatia

1:00 am on Dec 9, 2004 (gmt 0)

10+ Year Member



Excellent, thank you very much, that works great!

coopster

1:10 pm on Dec 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$pagename = str_replace('.','-detail.', basename [php.net]($_SERVER['PHP_SELF']));
2 lines less ;) ... hehe

jatar_k

5:53 pm on Dec 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ah, basename, that's what I was looking for

it has always astounded and annoyed me that the file name wasn't readily available in $_SERVER though.

photocroatia

11:32 am on Dec 11, 2004 (gmt 0)

10+ Year Member



That worked 100% until I implemented it into the photo gallery I use, what is happening is the filename that is being returned is the filename of the calling script.

for example.

gallery.php calls my script aa.php, when I echo the current file name inside aa.php it returns gallery.php I need it to retuen aa.php so that I can append aa-detail.php.

Thank you.

mincklerstraat

12:14 pm on Dec 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then maybe you could try:
$pagename = str_replace('.','-detail.', basename(__FILE__));

photocroatia

12:22 pm on Dec 11, 2004 (gmt 0)

10+ Year Member



Thank you very much, that works.