How can curl be properly used in PHP?

To properly use cURL in PHP, you need to initialize a cURL session using `curl_init()`, set the necessary options using `curl_setopt()`, execute the session with `curl_exec()`, and then close the session with `curl_close()`. This allows you to make HTTP requests, handle responses, and interact with external APIs or services.

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, 'https://api.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute cURL session
$response = curl_exec($ch);

// Close cURL session
curl_close($ch);

// Handle response
if($response){
    echo $response;
} else {
    echo 'Error: '.curl_error($ch);
}