Forum Moderators: coopster

Message Too Old, No Replies

read part of a url

         

th1chsn

3:32 pm on Feb 5, 2009 (gmt 0)

10+ Year Member



I'm trying to extract only a middle section from a URL. In the example below I would want the variable to return "whatever".

domain.com/whatever/page.php

Can someone help me with the syntax on how to do that?

Thanks in advance.

STeeL

4:22 pm on Feb 5, 2009 (gmt 0)

10+ Year Member



You can split your URL into peaces like this:

$path_array = explode("/", $_SERVER['REQUEST_URI']);

Debug your result like this:

echo "<pre>"; var_dump($path_array); echo "</pre>";

Depending on your server configuration $path_array[1] should return "whatever".