How can I parse a string like a = 1 & B = 2 in PHP?

Source: Internet
Author: User
Is there any good way to parse a string like a = 1 & B = 2 in PHP to solve a problem? an interface will return a = 1 & B = 2 & amp; c = 3 ...... the number of parameters in this format is not fixed, sometimes 10 or 20, and the order is not fixed, sometimes it is a = 1. could you tell me how to parse strings like a = 1 & B = 2 in PHP?
Encountered a problem

An interface returns a = 1 & B = 2 & c = 3 ...... the number of parameters in this format is not fixed, sometimes 10 or 20, and the order is not fixed, sometimes a = 1 & B = 2 & c = 3, sometimes B = 2 & a = 1 & c = 3

How can I easily obtain the value of a parameter, for example, I want to obtain the value of c in it

I tried to use explode to interrupt the string, but I felt that it was a pretty good thing. Can I use other functions directly? share with me:
------ Solution --------------------
$s='a=1&b=2&c=3';
parse_str($s,$ar);
print_r($ar);

Array
(
[A] => 1
[B] => 2
[C] => 3
)
------ Solution --------------------
$s = 'a=1&b=2&c=3';
parse_str($s, $a);
print_r($a);
Array
(
[A] => 1
[B] => 2
[C] => 3
)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.