Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl automatically display the result?

Tags:

I'm using php 5.3.2 and when i execute a curl it display the result directly without adding a print or echo function.

Here is my code:

<?php $pvars = array('query' => 'ice age', 'orderby' => 'popularity'); $timeout = 30; $myurl = "http://www.website.com"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $myurl); curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars); $xml = curl_exec($curl); curl_close ($curl); ?> 

What's wrong with my code and why it displays the result?

like image 395
Emily Avatar asked Apr 08 '10 00:04

Emily


1 Answers

By default, the curl extension prints out the result.

You need to enable the CURLOPT_RETURNTRANSFER option, like so:

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 

After that option is enabled, curl_exec will return the result, instead.

like image 134
Brian McKenna Avatar answered Oct 15 '22 19:10

Brian McKenna