using parse_url is returning only the first arg=value for $a['query'].  How do we get all elements?

Posted on 2005-05-10
Last Modified: 2008-03-17
We are using parse_url to decode a url into its components.

The function is working correctly except that it is returning only the first url variable.
For instance if we do:

$a['query'] returns only up to "pro=w".  We need it to return all elements of the request.  How do we do this?

Question by:mcm-mgm
    1 Comment
    LVL 27

    Accepted Solution

    hmm, don't know why you are seeing that output,

    $a = parse_url('');

    echo '<pre>';
    echo '</pre>';


        [scheme] => http
        [host] =>
        [path] => /catalog/proddetail.asp
        [query] => pro=w&langid=EN&dept=3&sku_id=0665000FS10048110&catid=11130&newdeptid=15

    Which is correct.

    Failing that you can get the current query string contents using: $_SERVER['QUERY_STRING']

    or, if you need to get it from a string URL rather then the current one you could use:

    $url = '';
    echo substr($url,strpos($url,'?')+1);


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now