如何从字符串中提取curl_exec信息

时间:2015-08-12 00:35:35

标签: php curl

$appID='xxxxx';
$restID='xxxx';

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data2);

$headers = array(
    'X-Parse-Application-Id: ' .$appID.'',
    'X-Parse-REST-API-Key: ' .$restID.'',
    'Content-Type: image/jpeg'       
    );

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_URL, xxxxx);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch); 

curl_exec()之后我得到了结果:

{"name":"xxxxxxxxxxxxxxxxxxxxxx","url":"http://xxxxxxxx.com"}

如何从字符串中提取网址info(http://xxxxxxxx.com)

2 个答案:

答案 0 :(得分:8)

之后

$response = curl_exec($ch); 

您可以尝试添加:

$result = json_decode($response);
echo $result->url; // or print_r($result);

答案 1 :(得分:3)

看起来你得到的回应是:

{"name":"xxxxxxxxxxxxxxxxxxxxxx","url":"http://xxxxxxxx.com"}

JSON。如果您想要获得响应的“网址”部分,首先需要使用json_decode对其进行解码,然后引用您想要的部分:$result->url

$result = json_decode($response);
echo $result->url;