p4plus2
03-11-2008, 11:34 PM
This is fairly simple based on what I hear, However I need to know if its possible to do that and get only the page your on without the file extension...
ex)
http://demo.com/randomdir/part_i_need.notthis
if this is possible to just get that part can somebody show me an example?
THANKS,
~p4plus2~
_Aerospace_Eng_
03-12-2008, 12:03 AM
Use http://us2.php.net/basename
p4plus2
03-12-2008, 09:16 PM
Thanks for the help!
for anybody who needs a similar code here it is:
<?php
$path = $_SERVER['REQUEST_URI'];
$extension = '.php';
$file = basename($path, $extension);
echo("$file");
?>
Or a more practical use(which is similar to how I am using it):
<?php
$path = $_SERVER['REQUEST_URI'];
$extension = substr(strrchr($path, '.'), 1);
$extension = "."."$extension";
$file = basename($path, $extension);
if($file == "index"){
echo('hello, and welcome to my site');
}
elseif($file == "random"){
echo('welcome to a random page!');
}
else{
die("unknown page");
}
?>
you can also change:
$extension = substr(strrchr($path, '.'), 1);
$extension = "."."$extension";
to this:
$extension = '.';
$extension .= substr(strrchr($path, '.'), 1);
just personal preference.