How does PHP extract the required information from a standard string? PHPcode {'status': '000000', 'message': 'OK', 'updatetime': '2017-10-200: 46: 21', 'ischeck ': '1', 'com': 'yuyun G', 'Nu '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;