jueves, 4 de diciembre de 2025

 $options = array(

    CURLOPT_URL => 'http://www.example.com/',

    CURLOPT_RETURNTRANSFER => true,  // boolean

    CURLOPT_HEADER => false,         // boolean

    CURLOPT_USERAGENT => ''          // empty string, will be filtered

);


// Filter only non-empty strings

$options = array_filter($options, fn($v) => gettype($v) === 'string' && strlen($v) > 0);


$ch = curl_init();

foreach($options as $opt => $val){

    curl_setopt($ch, $opt, $val);

}


$response = curl_exec($ch);

curl_close($ch);


curl

<?php
// Create a curl handle to a non-existing location
$ch = curl_init('http://404.php.net/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(curl_exec($ch) === false)
{
echo
'Curl error: ' . curl_error($ch);
}
else
{
echo
'Operation completed without any errors';

}


//echo $error =( curl_errno($ch)>0)?curl_error($ch).", error code :  ".curl_errno($ch):"All good";




?>