How can cURL output be stored in a variable instead of displaying in the browser?

To store cURL output in a variable instead of displaying it in the browser, you can use the `CURLOPT_RETURNTRANSFER` option in your cURL request. This option tells cURL to return the response as a string instead of outputting it directly. You can then store this response in a variable for further processing or display.

<?php
// Initialize cURL session
$ch = curl_init();

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

// Execute cURL session and store the response in a variable
$response = curl_exec($ch);

// Close cURL session
curl_close($ch);

// Output the stored response
echo $response;
?>