PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Jul 25, 2017 7:30 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri May 12, 2017 9:17 am 
Offline
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 102
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:

<?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]'>
";
   echo "</div>";
}

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

?>



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group