Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't Echo Out cURL

Tags:

php

curl

When I use this code:

$ch = curl_init($url); $statuses = curl_exec($ch); curl_close($ch); 

I am returned what I want, but if I just use that - $statuses is echoed out onto the page.

How can I stop this?

like image 861
tarnfeld Avatar asked Dec 16 '09 22:12

tarnfeld


People also ask

How do you ignore cURL output?

The curl command with the -o /dev/null option can be used to suppress the response body output. Something like this should be displayed. If you also want to supress the progress bar, the -s or --silent flag can be used. Now the curl command returns no output.

What does CURLOPT_ RETURNTRANSFER do?

CURLOPT_RETURNTRANSFER: Converts output to a string rather than directly to the screen.

How do I stop cURL requests?

Servers cannot block cURL requests per se, but they can block any request that they do not like. If the server checks for some parameters that your cURL request does not satisfy, it could decide to respond differently.

What is curl_ exec in PHP?

cURL is a PHP extension that allows you to use the URL syntax to receive and submit data. cURL makes it simple to connect between various websites and domains. Obtaining a copy of a website's material.


2 Answers

Put this on line 2:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
like image 61
Matt McCormick Avatar answered Sep 23 '22 03:09

Matt McCormick


Include this option before curl_exec()

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
like image 45
Dominic Barnes Avatar answered Sep 24 '22 03:09

Dominic Barnes