Php 从部分JSON和部分HTTP响应中提取数据

Php 从部分JSON和部分HTTP响应中提取数据,php,json,twitter,Php,Json,Twitter,我正在使用一个API,使用cURL我收到了一组数据 数据看起来一半是HTTP请求,一半是JSON。我不知道为什么它是混合的,但本质上我在执行var_dump时得到了这个响应: string(873) "HTTP/1.1 200 OK cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0 content-length: 153 content-type: application/json;char

我正在使用一个API,使用cURL我收到了一组数据

数据看起来一半是HTTP请求,一半是JSON。我不知道为什么它是混合的,但本质上我在执行
var_dump
时得到了这个响应:

string(873) "HTTP/1.1 200 OK cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0 content-length: 153 content-type: application/json;charset=utf-8 date: Mon, 10 Nov 2014 10:58:49 UTC expires: Tue, 31 Mar 1981 05:00:00 GMT last-modified: Mon, 10 Nov 2014 10:58:49 GMT ml: A pragma: no-cache server: tsa_b set-cookie: guest_id=v1%3A141561712923128379; Domain=.twitter.com; Path=/; Expires=Wed, 09-Nov-2016 10:58:49 UTC status: 200 OK strict-transport-security: max-age=631138519 x-connection-hash: 57175e4dba3d726bebb399072c225958 x-content-type-options: nosniff x-frame-options: SAMEORIGIN x-transaction: 2e4b8e053e615c75 x-ua-compatible: IE=edge,chrome=1 x-xss-protection: 1; mode=block {"token_type":"bearer","access_token":"AAAAAAAAAAAAAAAAAAAAAMVfbQAAAAAAK7qYRQOgdZ771TrJ6pZ7nugCwVQ%3DLKcongtwy3lcBDbPSEreC9DfhJk3Gm7qyQInqhFAxYvo1clv4S"}"
这是完整的数据返回。它的开头是HTTP信息,最后是部分JSON

我唯一需要的是
access\u令牌
数据

如果它只是JSON,那么我可以使用
JSON\u decode
来获取access\u令牌,但因为它在开始时获得了所有HTTP信息
JSON\u decode
无法理解它,并给出空结果

如何删除HTTP部分,以便只获取访问令牌数据

ETA:我的请求是通过cURL发出的,因此我要转储的var是
$response

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$auth_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$header = curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
curl_close($ch);
我收到的结果与Twitter文档中给出的预期结果大致相符,因此我不认为数据损坏/不正确:

输出:

object(stdClass)[1]
  public 'token_type' => string 'bearer' (length=6)
  public 'access_token' => string 'AAAAAAAAAAAAAAAAAAAAAMVfbQAAAAAAK7qYRQOgdZ771TrJ6pZ7nugCwVQ%3DLKcongtwy3lcBDbPSEreC9DfhJk3Gm7qyQInqhFAxYvo1clv4S' (length=112)

割台输出和拆卸开关

$header = curl_setopt($ch, CURLOPT_HEADER, 1);
或替换为

curl_setopt($ch, CURLOPT_HEADER, false);

谢谢,这太完美了。
curl_setopt($ch, CURLOPT_HEADER, false);