Putting cURL results in a variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Putting cURL results in a variable

Post by GeXus »

Anyone know how to do this without curl printing the results?

I'm doing this:

Code: Select all

 
$result = curl_exec($ch);
 
But this prints the results on the screen, without having to specifically print $result
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Putting cURL results in a variable

Post by onion2k »

I'm pretty sure it doesn't echo it. Are you sure you're not echoing $result somewhere later in the code? Stick "exit();" immediately after the call to curl_exec() ... if you get a bank page then it's not echoing.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Putting cURL results in a variable

Post by Weirdan »

Code: Select all

 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
onion2k wrote: I'm pretty sure it doesn't echo it.
Unfortunately you're wrong. By default curl_exec dumps everything it receives into standard output stream (that's being the webpage when you're running as apache module). CURLOPT_RETURNTRANSFER=true option tells it to not do so.
Post Reply