php字符串转数值问题?

string(898) "HTTP/1.1 200 OK Server: Tengine Date: Mon, 11 Feb 2019 13:31:34 GMT Content-Type: application/json; charset=UTF-8 Content-Length: 129 Connection: keep-alive Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH Access-Control-Allow-Headers: X-Requested-With,X-Sequence,X-Ca-Key,X-Ca-Secret,X-Ca-Version,X-Ca-Timestamp,X-Ca-Nonce,X-Ca-API-Key,X-Ca-Stage,X-Ca-Client-DeviceId,X-Ca-Client-AppId,X-Ca-Signature,X-Ca-Signature-Headers,X-Ca-Signature-Method,X-Forwarded-For,X-Ca-Date,X-Ca-Request-Mode,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range,Content-MD5 Access-Control-Max-Age: 172800 X-Ca-Request-Id: A88CA52A-DC91-4FFB-A9AB-8A4BD2CF30EC X-Powered-By: PHP/5.6.9 X-Ca-Error-Message: OK {"status":1,"data":{"raw_text":"1.png","raw_type":"QR-Code"},"msg":"success"}"
请问各位大侠,php这个字符串该怎么提取raw_text后面的‘1.png’这个数据
谢谢!
已邀请:

brean

赞同来自: 醒来

先转成数组。然后根据下标取值。
 
代码如下:
 
<?php

$str = 'HTTP/1.1 200 OK Server: Tengine Date: Mon, 11 Feb 2019 13:31:34 GMT Content-Type: application/json; charset=UTF-8 Content-Length: 129 Connection: keep-alive Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH Access-Control-Allow-Headers: X-Requested-With,X-Sequence,X-Ca-Key,X-Ca-Secret,X-Ca-Version,X-Ca-Timestamp,X-Ca-Nonce,X-Ca-API-Key,X-Ca-Stage,X-Ca-Client-DeviceId,X-Ca-Client-AppId,X-Ca-Signature,X-Ca-Signature-Headers,X-Ca-Signature-Method,X-Forwarded-For,X-Ca-Date,X-Ca-Request-Mode,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range,Content-MD5 Access-Control-Max-Age: 172800 X-Ca-Request-Id: A88CA52A-DC91-4FFB-A9AB-8A4BD2CF30EC X-Powered-By: PHP/5.6.9 X-Ca-Error-Message: OK {"status":1,"data":{"raw_text":"1.png","raw_type":"QR-Code"},"msg":"success"}';

echo json_decode('{'.substr($str,strpos($str,'{')+1),TRUE)['data']['raw_text'];

输入结果:
 
1.png

要回复问题请先登录注册