curl_setopt


php128 apg

SET an option for a cURL transfer.



<?php

bool curl_setopt
(CurlHandle $handleint $optionmixed $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($newCurlCURLOPT_URL$url);

// Return Page contents.
curl_setopt($newCurlCURLOPT_RETURNTRANSFERtrue);
 
$output curl_exec($newCurl);
 
echo 
$output;
?>

 RESULT   

SEE the next exercises - other lessons!