How To Analyze Url To Auto Add Appropriate Encoding On Appropriate Spots ?
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:
In this example, I need the $key array to be populated with:
And, I need the $value array to be populated with:
Then I need to echo each array’s values.
How to do this ?
I need to auto add the appropriate encoding functions in the submitted url. So now I won’t be echoing like this:
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.
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 ‘