我有以下代码
function curl($url) {
$options = Array(
CURLOPT_HEADER => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_AUTOREFERER => TRUE,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10,
CURLOPT_URL => $url,
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
$httpCode = curl_getinfo($ch);
curl_close($ch);
return $data;
}
如何返回数据以及被卷曲的网址的http状态代码?
答案 0 :(得分:0)
从函数返回一组数据的常用方法是使用数组,数字或关联。这可以这样做:
curl($url) {
// other codes here
return array($data, $httpCode);
}
// or
curl($url) {
// other codes here
return array(
'data' => $data,
'statusCode' => $httpCode
);
}