qadenza
qadenza

Reputation: 9293

Get file name if it's not part of url

url:

localhost/story/  

current file is index.php
Is there a way to get file name (index.php) in php, if it's not part of url.

basename(__FILE__) doesn't work because result is contact.php probably because contact.php is included at the beginning of index.php.

Upvotes: 0

Views: 50

Answers (3)

Jack jdeoel
Jack jdeoel

Reputation: 4584

__FILE__ will get current filename

echo basename(__FILE__);

The basename() function returns the filename from a path.

Upvotes: 2

webcitron
webcitron

Reputation: 142

@madankundu answer is ok, but you shouldn't access request variables directly. Better is:

echo basename(filter_input(INPUT_SERVER, 'PHP_SELF'));

Upvotes: -1

madankundu
madankundu

Reputation: 154

echo basename($_SERVER['PHP_SELF']);

Upvotes: 1

Related Questions