View Full Version : Get page name
acslater323
07-10-2006, 07:06 PM
How do you get the name of a page from the address bar using PHP?
e.g. http://www.somepage.com/about.htm
Return:
$page = "about";
erisco
07-10-2006, 07:07 PM
<?php echo $PHP_SELF; ?>
Is this what you want?...
acslater323
07-10-2006, 08:54 PM
Well, not really, because that spits back the whole path. I want just the filename minus the extension, as illustrated in my example above.
darksidepuffin
07-11-2006, 02:22 AM
try:
basename($_SERVER["REQUEST_URI"],'.php');
jabaro
07-11-2006, 03:32 PM
Just do $PHP_SELF and then parse it. look for the last occurance of '/' and the last occurance of '.' then use substr to get all in the stuff inbetween.
-i-dont-know-
07-11-2006, 04:06 PM
Could you use <?php echo $PHP_SELF; ?> and then get the basename() for it?
acslater323
07-11-2006, 04:21 PM
Either way should work. Thanks, guys.
darksidepuffin
07-11-2006, 04:30 PM
thats basically the same thing as my solution..except a different variable.
-i-dont-know-
07-11-2006, 05:08 PM
Oh yeah, I didn't see the basename function on your code.
erisco
07-11-2006, 05:15 PM
My bad. Heh.
*edited out*
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.