Forum Moderators: coopster

Message Too Old, No Replies

URL/Path parameters

         

hoover90

2:30 am on Jan 9, 2008 (gmt 0)

10+ Year Member



How does one go about getting parts of a hostname and URL path into PHP variables?

Example:
[1.example.com...]
http://example.com/2/3/4/5/

How do you get the values for 1-5?

[edited by: eelixduppy at 11:03 pm (utc) on Jan. 13, 2008]
[edit reason] delinked [/edit]

Habtom

5:40 am on Jan 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Combination of $_SERVER['REQUEST_URI'] and explode [php.net] functions.

And Welcome to WebmasterWorld.

hoover90

8:29 pm on Jan 9, 2008 (gmt 0)

10+ Year Member



Alright, I can see how I could get the 2-5 with the explode function, and I think #1 is just a matter of tinkering with the $_SERVER['SERVER_NAME'] variable and a string function or two.

Thanks!

hoover90

10:01 pm on Jan 9, 2008 (gmt 0)

10+ Year Member



Or I could just use explode for both, couldn't I?

:-)

PHP_Chimp

9:44 am on Jan 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is also parse_url [uk3.php.net] that you could use with

$url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";

Although all that is doing is giving you an associative array as opposed to the numeric array you get from explode.