Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to extract $_SERVER['REQUEST_URL'] from given url

for example

$url = 'http://localhost/application_dir/';

extract requested url from $url;

share|improve this question

closed as off topic by John Conde Sep 18 '12 at 11:22

Questions on Webmasters Stack Exchange are expected to relate to webmastering within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

This belongs on StackOverflow – Aurelio De Rosa Sep 18 '12 at 10:27
The relevant $_SERVER superglobal is REQUEST_URI (not _URL). – w3dk Sep 18 '12 at 11:03
up vote 2 down vote accepted

parse url is commonly used

$url = 'http://localhost/app/path/';


echo parse_url($url, PHP_URL_PATH);

if you wan't to extract path parameter from the output you can do as follow:

    $url = 'http://localhost/app/path/';

    $extract = parse_url($url);

    echo $extract['path'];
share|improve this answer
how to extract only 'path' – John Smiith Sep 18 '12 at 10:37
i updated answer – Liang Lee Sep 18 '12 at 10:42
Just to note, $_SERVER['REQUEST_URI'] (as stated in your question) is different from the path part of the URL. The REQUEST_URI includes the querystring as well, whereas path obviously does not. – w3dk Sep 18 '12 at 10:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.