php8.5
Home/ Manual/ curl / functions/ curl_strerror

curl_strerror

PHP function Edit on GitHub ✎

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

Return string describing the given error code

Description

curl_strerror(int $error_code): string|null

Returns a text error message describing the given error code.

Parameters

error_code

One of the cURL error codes constants.

Return Values

Returns error description or null for invalid error code.

Examples

curl_errno() example

php
<?php
// Create a curl handle with a misspelled protocol in URL
$ch = curl_init("htp://example.com/");

// Send request
curl_exec($ch);

// Check for errors and display the error message
if($errno = curl_errno($ch)) {
    $error_message = curl_strerror($errno);
    echo "cURL error ({$errno}):\n {$error_message}";
}
?>

The above example will output:

output
cURL error (1):
 Unsupported protocol

See Also

Source: reference/curl/functions/curl-strerror.xml · from the official PHP manual (php/doc-en)