Question

  • Creator
    Topic
  • #2141582

    How To Analyze Url To Auto Add Appropriate Encoding On Appropriate Spots ?

    by rahulsharmaa11199 ·

    Hey There,

    My question is I need to parse user submitted urls before echoing their submitted urls on my page. Need to parse the urls as I won’t know what urls they will be submitting nor the structures of their urls.
    On each submitted url, I need to add the key part of each query string on the $key array and the value part of each query string on the $value array. How to do this ?
    Example, a user submits this url:
    http://example.com/autos/cars/list.php?state=california&max_price=50000

    FIRST STEP
    In this example, I need the $key array to be populated with:
    state
    max_price

    And, I need the $value array to be populated with:
    california
    50000

    Then I need to echo each array’s values.
    How to do this ?

    SECOND STEP
    I need to auto add the appropriate encoding functions in the submitted url. So now I won’t be echoing like this:

    echo ‘http://example.com/autos/cars/list.php?state=california&max_price=50000’;

    But after parsing the url and after adding the appropriate encoding php functions in the correct spots of the url, I will be echoing like this:

    echo rawurlencode(‘http://example.com/autos/cars/list.php’) .’?state=’ .urlencode(‘california’) .’&max_price=’ .intval(50000);

    Did you notice that, I auto added rawurlencode on the file path and urlencode on the query string’s values and did you notice that I added intval where the query string’s value was an INT ?
    Now, I did all this additions manually here ofcourse to show you what I want php to do on auto-pilot.

    SUMMARY:
    Need to get php to auto analyze the url and auto add the rawurlencode(), urlencode() and intval() where appropriate.

    How to do this ?

    Once these two steps are achieved, then I can say a custom php function just got built that analyzes submitted urls and encodes the urls with the appropriate encoding functions (rawurlencode, urlencode, intval, etc).

    I don’t know how to start on this and so any code sample would be most appreciated.
    This bad code didn’t work. Failed attempt:

    print_r(parse_url($url)); echo ‘
    ‘;

    $keys = array(print_r(parse_url($url))); echo ‘
    ‘;

    foreach($keys as $key=>$value)
    {
    $key = array();
    $value = array();
    echo $key[‘0’]; echo ‘
    ‘;
    echo $value[‘0’]; echo ‘
    ‘;
    }

You are posting a reply to: How To Analyze Url To Auto Add Appropriate Encoding On Appropriate Spots ?

The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our Community FAQs for details. All submitted content is subject to our Terms of Use.

All Answers

  • Author
    Replies
    • #2415148

      That’s a start.

      by rproffitt ·

      In reply to How To Analyze Url To Auto Add Appropriate Encoding On Appropriate Spots ?

      I read your post a few times but what’s lacking and even if you fill it in will unlikely result in anyone submitting code for you are “more example URLs.”

      Also lacking is why you are doing this. This means:
      1. Without enough example URLs to test the parser no one can be sure it’s what you want.
      2. Without background on why you are doing this, no one can guess beyond the examples (you only supplied one example yet wrote ” I won’t know what urls they will be submitting nor the structures of their urls.)

      I would be guessing this is some sort of price tracker site but my bet is this is a bad guess.

      -> I suggest you find programming sites and submit much better specifications and examples along with how much the pay is. Remember that most want this to be a livable wage so lowballing the price usually gets you the worst code you’ll ever see.

Viewing 0 reply threads