How to get the second segment in URL without slashes ? For example I have a URL`s like this
http://foobar/first/second
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 www.example.com/user/account you will get 'user'
$segments = explode('/', trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With