How does the explode function convert a string into a multi-dimensional array?

Source: Internet
Author: User
How does the explode function convert a string into a multi-dimensional array? For example, I now have a string
$ Str = id @ 2title ** Me and You @ url ** http://baidu.com % id @ 3title ** Me and You 3 @ url ** http: // baidu. com3 % id @ 4title ** Me and You 4 @ url ** http: // baidu. com4
How to convert such a string into a multi-dimensional array.
Array (
[0] => array (
Id => 2
Title => Me and You
Url => http://baidu.com
)
[1] => array (
Id => 3
Title => Me and You 3
Url => http: // baidu. com3
)
..............
)


Reply to discussion (solution)

The format is incorrect!
From id @ 2title ** I and You
To
Id => 2
Title => Me and You
What is the basis?

The format is incorrect!
From id @ 2title ** I and You
To
Id => 2
Title => Me and You
What is the basis?


@ Use this symbol?

Yes?
@ Only indicates the separation of names and values
So what is the basis for dividing 2 titles into 2 and title?

$ Str = id @ 2 ** title @ Me and You ** url @ http://baidu.com % id @ 3 ** title @ me and you 3 ** url @ http: // baidu. com3 % id @ 4 ** title @ me and you 4 ** url @ http: // baidu. com4

The string was written incorrectly. this is correct. please kindly advise...

$ Str = 'Id @ 2 ** title @ Me and You ** url @ http://baidu.com % id @ 3 ** title @ me and you 3 ** url @ http: // baidu. com3 % id @ 4 ** title @ me and you 4 ** url @ http: // baidu. com4 '; foreach (explode (' % ', $ str) as $ v) {parse_str (str_replace (' @ ',' = ', str_replace ('**', '&', $ v), $ t); $ ar [] = $ t;} print_r ($ ar );

$ Str = 'Id @ 2 ** title @ Me and You ** url @ http://baidu.com % id @ 3 ** title @ me and you 3 ** url @ http: // baidu. com3 % id @ 4 ** title @ me and you 4 ** url @ http: // baidu. com4 '; foreach (explode (' % ', $ str) as $ v) {parse_str (str_replace (' @ ',' = ', str_replace ('**', '&', $ v), $ t); $ ar [] = $ t;} print_r ($ ar );



It's too cool, and the moderator is an online hacker !!!
Thank you.

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.