I want to split the parameters sent through URL. Here is my text.
"mytext=A & B Company&anothertext=20&texttwo=SampleText&array[1]=10&array[2]=20"
Expected output:
['mytext'=>'A & B Company', 'anothertext'=> 20, 'texttwo' => 'SampleText', array[1] => 10, array[2] => 20 ].
I tried with explode('&', $params) and parse_str($url_components['query'], $params);
both giving only A as result. I need as 'A & B Company'. How to achieve this?
I think you're looking for parse_str()?
See: https://3v4l.org/L2UZa
The result is:
This differs slight from what you want because of the
&. if you could replace the&with the URL encoded version%26it would work.See: https://3v4l.org/OXfsD
The result now is:
Basically the
&is an anomaly, it shouldn't have been there in the first place. URL query parameters should be made with urlencode(), or something equivalent, which would have replace&by%26.