Questions about changing the array of strings

Source: Internet
Author: User
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"
}
}
*/

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.