Parsing a directory from address url
How can I parse a directory out of a url? for instance the address bar reads http://www.sample.com/directory1/directory2/index.php How do开发者_如何学编程 I get the directory2 out of it from the address bar with PHP 4?
here's the code I figured out. not sure how to make the "10" a variable. That's the length of the first directory. I'm unsure how to get the position of the x occurance of "\". This worked, though it is not eloquent.
$url=$_SERVER['REQUEST_URI'];
$end=strrpos($url,'\\', 0);
$length=$end-10;
$directory=substr($url, 10, $length);
Using PHP, check out parse_url()
. Particularly the path
key.
精彩评论