Jump to content


Photo

getting end of url as string


  • Please log in to reply
3 replies to this topic

#1 erron

erron
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 18 July 2006 - 10:47 PM

hi,

can someone help me, i know how to get a site url and how to get part of a string, but what im finding difficult is getting the end of a url, for example:

http://www.mysite.com/mypage/index.php

from this, how would i get 'mypage' as a string?

#2 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 18 July 2006 - 10:58 PM

You mean the directory that index.php is in?

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#3 yonta

yonta
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 18 July 2006 - 11:11 PM

Don't know if there's a simpler solution (hope there is) but you could do this:

$path = 'http://www.mysite.com/example/index.php';
print substr(strrchr(dirname($path), '/'), 1); //will return example

If you want to just get the current directory (and not parse a url string), use <a href="http://pt.php.net/ge...cwd">getcwd</a> .

best
do it, do it right, do it right now

#4 erron

erron
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 19 July 2006 - 12:56 AM

Thanks guys,

tried that and a few other work arounds and settled with using str_replace and php_self




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users