Home > Backend Development > PHP Tutorial > PHP怎么从一段格式标准的字符串中提取自己需要的信息

PHP怎么从一段格式标准的字符串中提取自己需要的信息

WBOY
Release: 2016-06-13 13:11:01
Original
834 people have browsed it

PHP如何从一段格式标准的字符串中提取自己需要的信息?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
{ 'status':'200', 'message':'ok','updatetime':'2012-10-05 12:46:21','ischeck':'1','com':'yuantong','nu':'2636535819','state':'3','condition':'F00','data':[ {'time':'2012-07-09 13:22:02','context':'北京市海淀区中关村鼎好/PDA正常签收扫描/签收人:医院收发室 ','ftime':'2012-07-09 13:22:02'},{'time':'2012-07-08 12:39:58','context':'北京市海淀区中关村鼎好/留仓件入扫描节假日客户休息 ','ftime':'2012-07-08 12:39:58'},{'time':'2012-07-08 12:35:01','context':'北京市海淀区中关村鼎好/派件扫描/派件人:王一民 ','ftime':'2012-07-08 12:35:01'},{'time':'2012-07-08 11:05:08','context':'北京市海淀区中关村鼎好/下车扫描 ','ftime':'2012-07-08 11:05:08'},{'time':'2012-07-08 06:53:20','context':'北京市海淀区中关村/装件入车扫描 ','ftime':'2012-07-08 06:53:20'},{'time':'2012-07-08 05:09:31','context':'北京分拨中心/装件入车扫描 ','ftime':'2012-07-08 05:09:31'},{'time':'2012-07-07 22:26:21','context':'北京分拨中心/装件入车扫描 ','ftime':'2012-07-07 22:26:21'},{'time':'2012-07-07 22:22:13','context':'北京分拨中心/拆包扫描 ','ftime':'2012-07-07 22:22:13'},{'time':'2012-07-07 20:01:34','context':'北京市通州区城区/揽收扫描/取件人:王昌征 ','ftime':'2012-07-07 20:01:34'},{'time':'2012-07-07 17:35:24','context':'北京市通州区城区/业务员收件/取件人:张蒙 ','ftime':'2012-07-07 17:35:24'}]} 

Copy after login

想提取message的值,如此处是ok,还有最有一条记录的时间和内容,如此处分别是2012-07-07 17:35:24和北京市通州区城区/业务员收件/取件人:张蒙,该如何实现?

------解决方案--------------------
假定编码为utf-8的,否则还需$s=iconv('gbk', 'utf-8', $s);

$s = 你的那个串
$s = strtr($s, "'", '"'); //转成php可识别的 json
$t = json_decode($s);
echo $t->message; //ok
echo $t->data[9]->context; //北京市通州区城区/业务员收件/取件人:张蒙



------解决方案--------------------
你可以先用explode函数
------解决方案--------------------
PHP code

$current= strtr($current0, "'", '"');
$json = json_decode($current);
echo $json->message;
$length=count($json->data);;
$bottom=$length-1;
echo $json->data[$bottom]->context; <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template