How do you use cURL in PHP

cURL is a powerful tool for transferring data with URLs. In PHP, cURL is commonly used to make HTTP requests to external servers. You can send GET, POST, and other types of requests using cURL, which makes it a versatile tool for web development.

cURL, PHP, HTTP requests, data transfer, web development
Learn how to use cURL in PHP to make HTTP requests and handle responses effectively.

$curl = curl_init(); // Initialize cURL
curl_setopt($curl, CURLOPT_URL, "http://example.com"); // Set the URL
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Return the response as a string

$response = curl_exec($curl); // Execute the request

if ($response === false) {
    echo 'cURL Error: ' . curl_error($curl); // Handle error
} else {
    echo $response; // Print response
}

curl_close($curl); // Close cURL session
    

cURL PHP HTTP requests data transfer web development