georgevich georgevich - 5 months ago 39
PHP Question

Get second segment from url

How to get the second segment in URL without slashes ?
For example I have a URL`s like this


How to get the value where "first" stands ?


Use parse_url to get the path from the URL and then use explode to split it into its segments:

$uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri_segments = explode('/', $uri_path);

echo $uri_segments[0]; // for you will get 'user'