PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
bordman
Forum Newbie
Posts: 16 Joined: Thu Jan 26, 2006 8:20 am
Location: RI
Post
by bordman » Fri Feb 24, 2006 11:15 am
Hi,
I have the following code:
Code: Select all
<? $pagename = $_SERVER['PHP_SELF'] ;
if ($pagename == "index.php") {
$myimage = "image1.jpg" ;
} else {
$myimage = "image2.jpg" ;
}
?>
pagename returns /foldername/index.php
How can I split this up so I only get index.php
THANKS!!!
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Fri Feb 24, 2006 11:43 am
There's probably a predefined server variable
but you could try this
Code: Select all
<?php
function getPageName($phpself){
$pieces = explode("/",$phpself);
$num = count($pieces) - 1;
return $pieces[$num];
}
echo getPageName($_SERVER['PHP_SELF']);
?>
using this on /test/index.php returns
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 24, 2006 11:45 am
basename() works too.
bordman
Forum Newbie
Posts: 16 Joined: Thu Jan 26, 2006 8:20 am
Location: RI
Post
by bordman » Fri Feb 24, 2006 12:00 pm
basename() works perfect!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I was digging into a php reference site, that saves me some time!! THANKS!!!!!!!!!!!!