13
I recently had a problem identifying the current page.
Was using __FILE__
to get the current file, and used substr()
to retrieve the string after the last occurrence
bar, it turns out that in some operating systems these bars work differently and end up not returning the name in the expected way.
Is there any function/variable that already returns the file name ?
What I currently wear:
echo substr(__FILE__, strrpos(__FILE__, '\\') + 1, -4);
Used to use:
echo substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '/') + 1, -4);
I just learned:
echo basename($_SERVER['PHP_SELF'],'.php');
If it worked, mark my answer as correct. Thank you.
– William Okano