user8209518
user8209518

Reputation:

PHP-curl prints result instead of returning it

So my problem is that I am sending a curl request to a website and it's always printing the HTML response, for example:

<html><header>Example</header></html>

This is how I executed my curl:

$output = curl_exec($ch)

I did not echo out $output but it constantly returns the value over and over again.

Upvotes: 3

Views: 1865

Answers (1)

tobiv
tobiv

Reputation: 842

You need to set CURLOPT_RETURNTRANSFER to true:

CURLOPT_RETURNTRANSFER: TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.

You can do this with curl_setopt (quote above from this doc):

curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true )

Upvotes: 9

Related Questions