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.