天天看點

PHP curl_strerror函數

PHP cURL參考手冊

(PHP 5 >= 5.5.0)

curl_strerror — 傳回錯誤碼的描述。

說明

string curl_strerror ( int $errornum )
      

傳回錯誤碼的文本描述資訊。

參數

errornum

一個 » cURL 錯誤碼的常量。

傳回值

傳回錯誤碼描述資訊,非法錯誤碼傳回NULL 。

執行個體

<?php
// 建立一個拼寫錯誤的URL的cURL句柄
$ch = curl_init("htp://example.com/");

// 發送請求
curl_exec($ch);

// 檢查錯誤代碼并顯示錯誤資訊
if($errno = curl_errno($ch)) {
    $error_message = curl_strerror($errno);
    echo "cURL error ({$errno}):\n {$error_message}";
}

// 關閉句柄
curl_close($ch);
?>
      

以上例程會輸出:

cURL error (1):
 Unsupported protocol