469,290 Members | 1,941 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

how to get pagename from the URL in php

245 100+
Hey all,
i want to get the page name from the url. e.g.
My URL is
http://bytes.com/newthread.php

and i want to get page name newthread.php. How can i do that? Kindly help me out to sort out my problem.

Thanks in Advance

kind regards,
Mohsin Rafique
Mar 27 '09 #1
10 17529
Markus
6,050 Expert 4TB
Check out $_SERVER - PHP_SELF may be what you're looking for.
Mar 27 '09 #2
Amzul
130 100+
try parse_url() http://www.php.net/manual/en/function.parse-url.php
Mar 27 '09 #3
neovantage
245 100+
Sir both the things i know but i just want to get the page name only! not the whole URL or path or host name
Mar 27 '09 #4
Amzul
130 100+
Expand|Select|Wrap|Line Numbers
  1. $url ='http://bytes.com/newthread.php';
  2. $data = parse_url($url);
  3. echo $data['path'];
Mar 27 '09 #5
Dormilich
8,651 Expert Mod 8TB
you can check out the $_SERVER variables when you call phpinfo().
Mar 27 '09 #6
neovantage
245 100+
Sir in my case, my path is "rage/biz/site/products.php" and my url is "http://localhost/rage/biz/site/products.php"

As i am running application on my local machine by creating sub directories at the root folder. So in this case how can i get the pagename?
Mar 28 '09 #7
Dormilich
8,651 Expert Mod 8TB
get all characters after the last "/". strrpos() may be useful for that.
Mar 28 '09 #8
pbmods
5,821 Expert 4TB
Try running basename() on the path.

http://php.net/basename
Mar 28 '09 #9
neovantage
245 100+
Thank you very much. it resolved now
Mar 29 '09 #10
Found this on another website, gets all characters after last "/" this equals to pagename, for example it will echo "index.php" from

http://mywebsite.com/folder1/folder2/index.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function curPageName() {
  3.  return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
  4. }
  5.  
  6. echo "The current page name is ".curPageName();
  7. ?>
  8.  
Nov 17 '10 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by F. GEIGER | last post: by
1 post views Thread by Bent Biker | last post: by
3 posts views Thread by Dave | last post: by
3 posts views Thread by sasikumar | last post: by
5 posts views Thread by althafexcel | last post: by
1 post views Thread by =?Utf-8?B?ZG90TmV0RGF2ZQ==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.