$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://test.com");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'x=32423');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
'OK';
}
这是我在运行此页面时输出的内容
=的access_token AAAdsfsdfds32432fadfcazdfadsfadsfdas
如何提取此变量并将其传递给变量?
答案 0 :(得分:1)
你的战场上有一个拼写错误。后场应如下:
curl_setopt($ch, CURLOPT_POSTFIELDS, array('x'=>'32423'));
而不是:
curl_setopt($ch, CURLOPT_POSTFIELDS, 'x=32423'');
答案 1 :(得分:0)
听起来像你只是想要
$token = end(explode('=', $access_token_string));
答案 2 :(得分:0)
首先,您需要将CURLOPT_HEADERS更改为true,并且需要
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
和
$result=curl_exec($ch)
if( $result=== false)
然后,根据我在其他地方看到的答案,这应该得到标题:
list($headers,$content) = explode("\r\n\r\n",$result,2);
foreach (explode("\r\n",$headers) as $hdr)
print_r($hdr); //see what it gives you and then edit this accordingly.
echo $content;