How does PHP extract the required information from a standard string?

Source: Internet
Author: User
How does PHP extract the required information from a standard string? PHPcode {status: 200, message: OK, updatetime: 2012-10-0512: 46: 21, ischeck: 1, com: yuw.g, nu: 2636535819, state: 3, condition: how does PHP extract the required information from a standard string?
PHP code
  {'Status': '123', 'message': 'OK', 'updatetime': '2017-10-05 12:46:21 ', 'ischeck': '1 ', 'com ': 'yuyun G', 'Nu': '000000', 'State': '3', 'condition ': 'f00', 'data ': [{'Time': '2017-07-09 13:22:02 ', 'context': 'Normal reception scanning/Recipient: hospital reception room', 'ftime ': '2017-07-09 13:22:02 '}, {'Time': '2017-07-08 12:39:58', 'context ': 'customer breaks during/out-of-stock scanning holidays in Zhongguancun, Haidian district, Beijing', 'ftime': '2017-07-08 12:39:58 '}, {'Time ': '2017-07-08 12:35:01 ', 'context': 'Wang Yimin, 'ftime', Zhongguancun, Haidian district, Beijing, China ': '2017-07-08 12:35:01 '}, {'Time': '2017-07-08 11:05:08', 'context': 'Zhongguancun Dinghao/get off scanning in Haidian district, Beijing ', 'ftime': '2017-07-08 11:05:08 '}, {'Time': '2017-07-08 06:53:20', 'context ': 'Zhongguancun, Haidian district, Beijing, installation and car scanning ', 'ftime': '2017-07-08 06:53:20'}, {'Time': '2017-07-08 05:09:31 ', 'context': 'Beijing dial-out center/Assembly car scanning ', 'ftime': '2017-07-08 05:09:31'}, {'Time ': '2017-07-07 22:26:21 ', 'context': 'Beijing dial-out center/assembly-in-vehicle scanning', 'ftime': '2017-07-07 22:26:21 '}, {'Time': '2017-07-07 22:22:13 ', 'context': 'Beijing dial-out center/package splitting scan', 'ftime ': '2017-07-07 22:22:13 '}, {'Time': '2017-07-07 20:01:34', 'context': 'Tongzhou district, Beijing city/scanning/recipient: wang Changzheng ', 'ftime': '2017-07-07 20:01:34'}, {'Time': '2017-07-07 17:35:24 ', 'context ': 'Zhang Meng', 'ftime': '2017-07-07 17:35:24 '}]}

If you want to extract the message value, this is OK, and there is a record of the time and content, such punishment is 17:35:24 and Beijing Tongzhou District/salesman receiving/Recipient: Zhang Meng, how to implement it?

------ Solution --------------------
Assume that the code is utf-8. otherwise, $ s = iconv ('gbk', 'utf-8', $ s) is required );

$ S = your string
$ S = strtr ($ s, "'",' "'); // Convert it to a json file that can be recognized by php.
$ T = json_decode ($ s );
Echo $ t-> message; // OK
Echo $ t-> data [9]-> context; // receiver: Zhang Meng, district, Tongzhou district, Beijing, China



------ Solution --------------------
You can use the explode function first.
------ Solution --------------------
PHP code
$current= strtr($current0, "'", '"');$json = json_decode($current);echo $json->message;$length=count($json->data);;$bottom=$length-1;echo $json->data[$bottom]->context; 

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.