Questions about changing the array of strings $ s = "Stream & nbsp; water & nbsp; No.: JH0019 & nbsp; status: Processing & nbsp; & nbsp; Grade & nbsp;: high & nbsp; Time: & nbsp; 2013-05-28 & nbsp; 12:55:29 "how to convert the array structure to array ([serial number] = & gt; how to change the array of strings in JH0
$ S = "Stream ID: JH0019 state: Processing medium level: High time: 12:55:29"
How to convert to array structure
Array (
[Serial number] => JH0019
[Status] => processing in progress
[Level] => High
[Time] => 12:55:29
)
My thinking is:
Change "" first |
Modify |
Modify: |:
Modify |:
But I don't know how to remove the spaces between the time space and the streaming water number.
Last use
$ A = array ();
Foreach (explode ('|', $ s) as $ s ){
List ($ k, $ v) = explode (':', $ s );
$ A [$ k] = $ v ;}
I have already been dizzy. please help me to figure out the result. thank you.
Share To: JH0019 [... 'data-pics = ''>
------ Solution --------------------
$ S = "Stream ID: JH0019 state: Processing medium level: High time: 12:55:29 ";
$ A = preg_split ('/: \ s * ([\ d:-] +
------ Solution --------------------
\ S +)/', $ s,-1, PREG_SPLIT_DELIM_CAPTURE
------ Solution --------------------
PREG_SPLIT_NO_EMPTY );
Foreach (array_chunk ($ a, 2) as $ r ){
$ Res [preg_replace ('/\ s
------ Solution --------------------
/', '', $ R [0])] = $ r [1];
}
Print_r ($ res );
Array
(
[Serial number] => JH0019
[Status] => processing in progress
[Level] => High
[Time] => 12:55:29
)
------ Solution --------------------
$ S = "Stream ID: JH0019 state: Processing medium level: High time: 12:55:29 ";
Preg_match_all ('/([^:] +) :( [^ \ s] +)/', $ s, $ m );
Echo'';
Var_dump ($ m );
/**
Output result:
Array (3 ){
[0] =>
Array (3 ){
[0] =>
String (20) "Stream ID: JH0019"
[1] =>
String (24) "status: processing"
[2] =>
String (15) "grade: High"
}
[1] =>
Array (3 ){
[0] =>
String (11) "Stream ID"
[1] =>
String (12) "status"
[2] =>
String (9) "grade"
}
[2] =>
Array (3 ){
[0] =>
String (6) "JH0019"
[1] =>
String (9) "processing"
[2] =>
String (3) "high"
}
}
*/