douxuanyi2813
2018-08-21 15:35
浏览 39
已采纳

从卷曲中解析字符串

<?php 

$curl = curl_init();

    curl_setopt_array($curl, array(
  CURLOPT_URL => "",
  //return the transfer as a string
  CURLOPT_RETURNTRANSFER => true,
  //enable headers
  CURLOPT_HEADER => true,
  //get only headers
  CURLOPT_NOBODY => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Accept: application/json",
    "password: ",
    "username: "
  ),
));
// $response contains the output string
$response = curl_exec($curl);

$err = curl_error($curl);

curl_close($curl);

print_r($response);

?>

I am trying to take $response and truncate data from it.My output of $response is

HTTP/1.1 200 OK Server: Apache-Coyote/1.1 access-token: a3581f021476e4fb406c6b7c79e4095cece5d0c6 token-expiration-hours: 24 Content-Type: application/json Content-Length: 0 Date: Tue, 21 Aug 2018 14:12:27 GMT

I would like $response to just be the value of the access-token a3581f021476e4fb406c6b7c79e4095cece5d0c6

图片转代码服务由CSDN问答提供 功能建议

 &lt;?php 
 
 $ curl = curl_init(); 
 
 curl_setopt_array(  $ curl,array(
 CURLOPT_URL =&gt;“”,
 //将传输​​作为字符串返回
 CURLOPT_RETURNTRANSFER =&gt; true,
 //启用标题
 CURLOPT_HEADER =&gt; true,
 // 只获取标题
 CURLOPT_NOBODY =&gt; true,
 CURLOPT_ENCODING =&gt;“”,
 CURLOPT_MAXREDIRS =&gt; 10,
 CURLOPT_TIMEOUT =&gt; 30,
 CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
 CURLOPT_CUSTOMREQUEST =&gt;  “GET”,
 CURLOPT_HTTPHEADER =&gt;数组(
“接受:application / json”,
“密码:”,
“用户名:”
),
)); 
 // $ response 包含输出字符串
 $ response = curl_exec($ curl); 
 
 $ err = curl_error($ curl); 
 
 ncurl_close($ curl); 
 
print_r($ response); 
 
  ?&gt; 
   
 
 

我正在尝试接受$ response并从中截断数据。$ response的输出是

   HTTP / 1.1 200 OK服务器:Apache-Coyote / 1.1访问令牌:a3581f021476e4fb406c6b7c79e4095cece5d0  c6 token-expiration-hours:24 Content-Type:application / json Content-Length:0 Date:Tue,21 Aug 2018 14:12:27 GMT 
   
 
 

我希望$ response只是访问令牌的值 a3581f021476e4fb406c6b7c79e4095cece5d0c6

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题