curl_setopt


php128 apg

SET an option for a cURL transfer.



<?php

bool curl_setopt
(CurlHandle $handle, int $option, mixed $value);

$handle = A cURL handle

$option 
= The cURL option

$value 
= The value to be set on option

?>

 $handle 


The cURL handle returned by curl_init function.


 $option 


The CURLOPT_XXX option to be set.


 $value 


The value to be set on option.

This value must be NULL or STRING.


  1 EXERCISE   

<?php
//URL from which to get webpage contents.
$url = "https://news.google.com/";
// Initialize a CURL session.
$newCurl = curl_init();
 
//grab URL and pass it to the variable.
curl_setopt($newCurl, CURLOPT_URL, $url);

// Return Page contents.
curl_setopt($newCurl, CURLOPT_RETURNTRANSFER, true);
 
$output = curl_exec($newCurl);
 
echo 
$output;
?>

 RESULT   

SEE the next exercises - other lessons!