Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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
    
This belongs on StackOverflow –  Aurelio De Rosa Sep 18 '12 at 10:27
1  
The relevant $_SERVER superglobal is REQUEST_URI (not _URL). –  w3d Sep 18 '12 at 11:03
add comment

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.

1 Answer

up vote 2 down vote accepted

parse url is commonly used

<?php
$url = 'http://localhost/app/path/';

print_r(parse_url($url));

echo parse_url($url, PHP_URL_PATH);
?>

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

    <?php
    $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. –  w3d Sep 18 '12 at 10:56
add comment

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