Snippets → PHP → Get Current File Name Get Current File Name Chris Coyier on Jul 15, 2012 <?php $pageName = basename($_SERVER['PHP_SELF']); ?> Potential use: <body id="body_<?php echo $pageName; ?>"> Append ID to body to do different CSS styles on different pages.
Chris your snippets section is working. I found this on Google it was just what I needed.
http://www.expertcore.org/viewtopic.php?f=67&p=1453 has two solutions
sweet
yeah! this is working, thank you.
echo $pageName = basename($_SERVER[‘SCRIPT_NAME’]);
It will give current file name… as index.php or about.php
But you will have ‘.php’ as id or class. If you want get only name befor the ‘.php’ here is de code:
I agree. Simply I enclose files with regular dot(s) in the name:
better yet:
echo basename($_SERVER['REQUEST_URI'], '.php');
great, thank you
Yo…Hilco – thanks.
This rocks for my purposes…dynamically searching a database for stuff that’s only meant to be shown on certain pages.
? http://php.net/manual/en/language.constants.predefined.php .
You have an error in your code, $_SERVER[PHP_SELF] instead of $_SERVER[‘PHP_SELF’]
fixed
never know how these php snippets work
any link to demo to show few site, with the screencapture on the SERVER code that php was implemented
got very confuse, that these things work or NOT
A very useful feature that seems totally absent in Javascript.