Solution for converting regular 2D array to josn

Source: Internet
Author: User
Convert the regular 2D array to josnHTMLcode & lt; p & gt; & amp; middot; 2012-05-2920: 51: 50 & lt; br/& gt; accepted, the signer is the flag & lt;/p & gt; & lt; p & gt; & amp; middot; 2012-05-28 regular 2D array to josn
HTML code
  

· 2012-05-29 20:51:50
Accepted. the recipient is a draft.

· 21:16:17, 2012-05-28
[Xinjiang Kuitun company] has scanned [difficult parts]. cause: [customer requested to change delivery]

· 11:30:21, 2012-05-28
[Xinjiang Kuitun company]'s dispatcher [Wang Huiquan] is dispatching

· 11:13:10, 2012-05-28
The Courier has arrived at [Xinjiang Kuitun company]. the scanner is [Xinjiang Kuitun]. The Last Station is 【]

· 2012-05-26 05:56:59
Sent by [XinJiang Urumqi Aviation Department] to [Xinjiang Kuitun Company]

· 2012-05-26 05:56:59
Sent by [XinJiang Urumqi transit department] to [Xinjiang Kuitun Company]

· 2012-05-23 21:47:13
[Zhejiang Ningbo aviation department] is conducting [bagging] scanning

· 2012-05-23 21:47:13
[Zhejiang Ningbo Aviation Department] to [XinJiang Urumqi Aviation Department]

· 2012-05-23 21:44:03
The Courier has arrived at [Zhejiang Ningbo Aviation Department]. the scanner is [weighing 3]. The Last Station is [Zhejiang Ningbo Jiangbei company]

· 2012-05-23 20:10:59
From [Zhejiang Ningbo Jiangbei company] to [Zhejiang Ningbo Aviation Department]

· 2012-05-23 20:09:48
[Zhejiang Ningbo Jiangbei company] receiver [Niu Degui] received


This is the data. you need to use php to convert it into a two-dimensional array and then convert it into a josn output. Hope to output
Java code
  {"Status": "1", "data": [{"time": "20:51:50", "context": "accepted, the recipient is a draft ", "ftime": "20:51:50" },{ "time": "21:16:17", "context": "[Xinjiang Kuitun company] has scanned [difficult parts, cause of problem: [customer request change delivery] "," ftime ":" 21:16:17 "},{" time ":" 11:30:21 "," context ": "[Xinjiang Kuitun company] dispatching personnel [Wang Huiquan] dispatching", "ftime": "11:30:21" },{ "time": "11:13:10 ", "context": "The Courier has arrived in [Xinjiang Kuitun company]. the scanner is [] on the [Xinjiang Kuitun company]," ftime ":" 11:13:10 "}, {"time": "05:56:59", "context": "sent by [XinJiang Urumqi Aviation Department] to [Xinjiang Kuitun company]", "ftime": "05:56:59 "}, {"time": "05:56:59", "context": "sent by [XinJiang Urumqi transit department] to [Xinjiang Kuitun company]", "ftime": "05:56:59 "}, {"time": "21:47:13", "context": "[Zhejiang Ningbo Aviation Department] scanning", "ftime": "21:47:13 "}, {"time": "21:47:13", "context": "sent by [Zhejiang Ningbo Aviation Department] to [XinJiang Urumqi Aviation Department]", "ftime": "21:47:13 "}, {"time": "21:44:03", "context ": "The Courier has arrived at [Zhejiang Ningbo Aviation Department]. the scanner is [weighing 3]. The Last Station is [Zhejiang Ningbo Jiangbei company]", "ftime": "21:44:03 "}, {"time": "20:10:59", "context": "sent by [Zhejiang Ningbo Jiangbei company] to [Zhejiang Ningbo Aviation Department]", "ftime": "20:10:59 "}, {"time": "20:09:48", "context": "Niu Degui, receiver of [Zhejiang Ningbo Jiangbei company] received", "ftime ": "2012-05-23 20:09:48"}]}


------ Solution --------------------
PHP code
$ S ='

· 2012-05-29 20:51:50
Accepted. the recipient is a draft.

· 21:16:17, 2012-05-28
[Xinjiang Kuitun company] has scanned [difficult parts]. cause: [customer requested to change delivery]

· 11:30:21, 2012-05-28
[Xinjiang Kuitun company]'s dispatcher [Wang Huiquan] is dispatching

· 11:13:10, 2012-05-28
The Courier has arrived at [Xinjiang Kuitun company]. the scanner is [Xinjiang Kuitun]. The Last Station is 【]

· 2012-05-26 05:56:59
Sent by [XinJiang Urumqi Aviation Department] to [Xinjiang Kuitun Company]

· 2012-05-26 05:56:59
Sent by [XinJiang Urumqi transit department] to [Xinjiang Kuitun Company]

· 2012-05-23 21:47:13
[Zhejiang Ningbo aviation department] is conducting [bagging] scanning

· 2012-05-23 21:47:13
[Zhejiang Ningbo Aviation Department] to [XinJiang Urumqi Aviation Department]

· 2012-05-23 21:44:03
The Courier has arrived at [Zhejiang Ningbo Aviation Department]. the scanner is [weighing 3]. The Last Station is [Zhejiang Ningbo Jiangbei company]

· 2012-05-23 20:10:59
From [Zhejiang Ningbo Jiangbei company] to [Zhejiang Ningbo Aviation Department]

· 2012-05-23 20:09:48
[Zhejiang Ningbo Jiangbei company] receiver [Niu Degui] received

'; $ Arr = array ("message" => "OK", "ischeck" => "1", "updatetime" => "13:40:22 ", & quot; status & quot; = & quot; 200 & quot;); preg_match_all ('/

(. *) <\/P>/U', $ s, $ m); foreach ($ m [1] as $ v) {$ t = preg_split ('/[· ] +/', $ V,-1, PREG_SPLIT_NO_EMPTY); $ ar [] = array ('time' => $ t [0], 'context' => $ t [2], 'ftime' => $ t [0]);} array_push ($ arr, $ ar); echo json_encode ($ arr );

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.