sol sol - 1 year ago 166
PHP Question

PHP - parse current URL

I need to parse the current url so that, in either of these cases:

I can get the return value of "abc" (or whatever text is in that position). How can I do that?

Answer Source

You can use parse_url();

$url = '';


echo parse_url($url, PHP_URL_PATH);

which would give you

    [scheme] => http
    [host] =>
    [path] => /abc/

Update: to get current page url and then parse it:

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
 } else {
 return $pageURL;


echo parse_url($url, PHP_URL_PATH);

source for curPageURL function

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download