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

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

Jun 13, 2016 pm 01:11 PM
context time

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

PHP code

1

2

3

4

5

6

7

<!--

 

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

1

2

3

4

5

6

7

8

9

10

11

$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
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Monotonic clock processing of time package Monotonic clock processing of time package Aug 04, 2023 pm 05:45 PM

Today we are mainly going to take a look at the time application method of golang time package. The general rule between the two is that "wall time" is used to tell time, and "monotonic clock" is used to measure time; there are other clock processing methods.

How to use context to implement request caching in Go How to use context to implement request caching in Go Jul 22, 2023 pm 10:51 PM

How to use context to implement request caching in Go Introduction: When building web applications, we often need to cache requests to improve performance. In the Go language, we can use the context package to implement the request caching function. This article will introduce how to use the context package to implement request caching, and provide code examples to help readers better understand. What is context? : In the Go language, the context package provides a way to pass between multiple goroutines

What does context mean? What does context mean? Aug 04, 2023 pm 05:27 PM

Context is the environment and status information when the program is executed. It can include a variety of information, such as the value of variables, the call stack of functions, the execution location of the program, etc., allowing the program to make corresponding decisions based on different contexts. and perform corresponding operations.

How to use context to pass request parameters in Go How to use context to pass request parameters in Go Jul 22, 2023 pm 04:43 PM

The context package in the Go language is used to pass request context information in the program. It can pass parameters, intercept requests and cancel operations between functions across multiple Goroutines. To use the context package in Go, we first need to import the "context" package. Below is an example that demonstrates how to use the context package to implement request parameter passing. packagemainimport("context&quot

How to use context to implement request timeout control in Go How to use context to implement request timeout control in Go Jul 21, 2023 pm 12:18 PM

How to use context to implement request timeout control in Go Introduction: When we make network requests, we often encounter request timeout problems. A network request that does not respond for a long time will not only waste server resources, but also affect overall performance. In order to solve this problem, the Go language introduced the context package, which can be used to implement request timeout control. This article will introduce how to use the context package to implement request timeout control in Go, and attach corresponding code examples. 1. Understand the context package co

How to use context to implement request link tracking in Go How to use context to implement request link tracking in Go Jul 21, 2023 pm 05:57 PM

How to use context to implement request link tracking in Go. In the microservice architecture, request link tracking is a very important technology that is used to track the delivery and processing of a request between multiple microservices. In the Go language, we can use the context package to implement request link tracking. This article will introduce how to use context for request link tracking and give code examples. First, we need to understand the basic concepts and usage of the context package. The context package provides a mechanism

How to use context to implement timeout control in Go How to use context to implement timeout control in Go Jul 21, 2023 pm 02:28 PM

How to use context to implement timeout control in Go Introduction: Timeout control is a very important technology when writing concurrent programs. When the program needs to perform an operation, if the operation cannot be completed within the specified time, we hope to be able to interrupt it and perform other processing. In the Go language, we can use the context package to implement timeout control. Introduction to context Context is a mechanism in the Go language specifically designed to handle concurrent tasks. It can be used to pass cancellation signals and timeout signals

How to use context to implement request encapsulation and decapsulation in Go How to use context to implement request encapsulation and decapsulation in Go Jul 21, 2023 pm 05:01 PM

How to use context to implement request encapsulation and decapsulation in Go. In the development of Go language, we often encounter situations where we need to encapsulate and decapsulate some request parameters. This situation is especially common in complex systems, where we need to pass request parameters to different functions and modules, and there may be nested calls between these functions and modules. In order to facilitate the management and delivery of these request parameters, we can use the context package in Go to implement request encapsulation and decapsulation. The context package is the Go language

See all articles