Page 1 of 1

Error: Use of undefined constant RETURNTRANSFER

Posted: Fri May 12, 2017 9:17 am
by UniqueIdeaMan
Hi,

Does anyone have a clue why I get the following error in my further following code ?

Notice: Use of undefined constant RETURNTRANSFER - assumed 'RETURNTRANSFER' in C:\xampp\htdocs\test\curl.php on line 27

Warning: curl_setopt() expects parameter 2 to be integer, string given in C:\xampp\htdocs\test\curl.php on line 27

You are welcome to rectify the code where I'm goign wrong and then show me how it should have been.
I actually, copied this from a youtube tutorial and they don;t get any errors but I do! Absurd! I copied it while I was learning the basics of cURL.

Code: Select all


<?php 

// Youtube Channel: Clever Techie; Video: PHP cURL Tutorial - Learn PHP Programming.

// 1). Create cURL resource.
$curl = curl_init();

// 2). Set cURL options.
curl_setopt($curl, CURLOPT_URL, 'http://www.google.com');

// 3). Run cURL (execute http request).
curl_exec($curl);

// 4). Close cURL resource.
curl_close($curl);


// 1). $curl is going to be data type curl resource.
$curl = curl_init();

$search_string = "movies 2017";
$url = "https://www.amazon.com/s/field-keywords=$search_string";

// 2). Set cURL options.
curl_setopt($curl, CURLOPT_URL, 'https://www.amazon.com');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, RETURNTRANSFER, true);

// 3). Run cURL (execute http request).
$result = curl_exec($curl);
preg_match_all("!https://images-na.ssl-images-amazon.com/images/I/[^\s]*?._AC_US_160_.jpg!, $result, $matches");

//Use either one of the following 4 codes. (Use one by one in order to test and learn).

//code 1:
print_r($matches);

//code 2:
$images = array_unique($matches[0]);
print_r($images);

//code 3:
$images = array_values(array_unique($matches[0]));
print_r($images);

//code 4:
$images = array_values(array_unique($matches[0]));
for ($i = 0; $i < count ($images); $i++) {
    echo "<div style='float:left; margin: 10 0 0 0; '>";
    echo "img src='$images[$i]'><br />";
	echo "</div>";
}

// 4). Close cURL resource.
curl_close($curl);

?>