3

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.

3
  • Are you sure you don't print it? What's the code around this line – conditions, loops? Commented Oct 22, 2017 at 17:35
  • It's just curling to the website normally and nothing else. I don't echo anything. Commented Oct 22, 2017 at 17:35
  • Make sure you learn the difference between outputting and returning values. Commented Oct 22, 2017 at 18:18

1 Answer 1

9

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 )
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I appreciate your assistance.
Currently, I am trying to fetch string using CURLOPT_RETURNTRANSFER set to true. But, instead of resulting result.. it is returning empty array. Do you have any suggestion please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.