
- Forum
- Programming Talk
- PHP
- Get Pagename From URL
Get Pagename From URL
This is a discussion on Get Pagename From URL within the PHP forums, part of the Programming Talk category; hi, How to get the page name from the Url.For Example My urls is like exforsys . com/viewtopic.php Then how ...
-
Get Pagename From URL
hi,
How to get the page name from the Url.For Example My urls is like exforsys . com/viewtopic.php
Then how to get page name viewtopic.php. How can i do that?
Thanks,
Surya
-
Use this basename() on the path.
Example :
<?php
$path = "/home/httpd/html/index.php";
$file = basename($path); // $file is set to "index.php"
$file = basename($path, ".php"); // $file is set to "index"
?>
-
01-28-2010, 06:02 AM #3
- Join Date
- Jan 2010
- Answers
- 2
You can try following function to get the page name from the url....
The following code will first get the whole url and finally you will get the page name.......
<?php
function currentPageURL() {
$curpageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$curpageURL.= "s";}
$curpageURL.= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$curpageURL.= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$curpageURL.= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$file = basename($curpageURL);
return $file;
}
echo currentPageURL();
?>
-
Sponsored Ads

Reply With Quote





