How to parse such strings

Source: Internet
Author: User
How to parse such a string is a line of string below the file: [& nbsp; 00:00:00] & nbsp; 218.200.244.69 & nbsp;-& nbsp; & quot; how to parse strings such as GET & nbsp;/cmcc/ani/klyt_detail_at.jsp
Below is a line of strings in the file:
[00:00:00] 218.200.244.69-"GET/cmcc/ani/klyt_detail_at.jsp? Notify = 1 & type = video & id = 10477 & sid = GUIBWqU0F57trFtS & dirid = 0428100540 & p = 1 & session = & MISC_ID = 999 & MISC_SessionID = 999-df1b2815! 1434701435! 1257454712! 1185897536315 & MISC_ServiceID = 30070881 & MISC_AccessMode = 2 & MISC_MID = 00110080331963 HTTP/1.0 "200 8376"-"" TSD-TP005 "wap.chinam.com 1


I want to retrieve the following data. let's take a look at how to parse it:
[00:00:00]
218.200.244.69
-
-
"GET/cmcc/ani/klyt_detail_at.jsp? Notify = 1 & type = video & id = 10477 & sid = GUIBWqU0F57trFtS & dirid = 0428100540 & p = 1 & session = & MISC_ID = 999 & MISC_SessionID = 999-df1b2815! 1434701435! 1257454712! 1185897536315 & MISC_ServiceID = 30070881 & MISC_AccessMode = 2 & MISC_MID = 00110080331963 HTTP/1.0"
200
8376
-
TSD-TP005"
Wap.chinam.com
1

------ Solution --------------------

$ Html = "[00:00:00] 218.200.244.69 --\"
GET/cmcc/ani/klyt_detail_at.jsp? Notify = 1 & type = video & id = 10477 & sid = GUIBWqU0F57trFtS
& Dirid = 0428100540 & p = 1 & session = & MISC_ID = 999 & MISC_SessionID = 999-df1b2815! 1434701435!
1257454712! 1185897536315 & MISC_ServiceID = 30070881 & MISC_AccessMode = 2 & MISC_MID = 00110080331963
HTTP/1.0 \ "200 8376 \"-\ "\" TSD-TP005 \ "wap.chinam.com 1 ";

$ Match = '/\ [([^] *) \] ([^ "] *) \" ([^ "] *) \"/is ';
$ Re = preg_match_all (
$ Match,
$ Html,
$ Out );
Print_r ($ out );
Echo $ re;

?>
The subsequent photos are written as follows:
------ Solution --------------------
Refer:
====================================
$ Str = '[00:00:00] 218.200.244.69-"GET/cmcc/ani/klfyt_detail_at.jsp? Notify = 1 & type = video & id = 10477 & sid = GUIBWqU0F57trFtS & dirid = 0428100540 & p = 1 & session = & MISC_ID = 999 & MISC_SessionID = 999-df1b2815! 1434701435! 1257454712! 1185897536315 & MISC_ServiceID = 30070881 & MISC_AccessMode = 2 & MISC_MID = 00110080331963 HTTP/1.0 "200 8376"-"" TSD-TP005 "wap.chinam.com 1 ';

$ Arr = preg_match_all ('/(\ "(. [^ \"] *?) \ ") | (\ [(. [^ \] *?) \]) | (\ S (. [^ \ s +] *?) \ S) | (. [^ \ s] *)/', $ str, $ m );
Print_r ($ m [0]);
------ Solution --------------------
$ S = < [00:00:00] 218.200.244.69-"GET/cmcc/ani/klyt_detail_at.jsp? Notify = 1 & type = video & id = 10477 & sid = GUIBWqU0F57trFtS &
Dirid = 0428100540 & p = 1 & session = & MISC_ID = 999 & MISC_SessionID = 999-df1b2815! 1434701435! 1257454712! 1185897536315 & MISC_ServiceID = 3007
0881 & MISC_AccessMode = 2 & MISC_MID = 00110080331963 HTTP/1.0 "200 8376"-"" TSD-TP005 "wap.chinam.com 1
H;
$ R = preg_split ("/\ s +/", $ s );
Print_r ($ r );

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.