1

When I use CocoaRestClient to submit a GET on an HTML website it will return the source for the site. How can I return the same thing as a string (or something to convert into a string or parse) in php? I've tried using

    echo $_GET[$url];

but it does not seem to return anything.

Note: the string returned will probably be rather large.

3
  • Is there anyhing in $_get? Also try url rather than $url Commented Feb 17, 2013 at 18:27
  • Did you mean echo $_GET["url"]? Note however that there are limits on how big a GET parameter can be (about 1-2k) Commented Feb 17, 2013 at 18:28
  • $_GET['url']; will be what is in the url: index.php?url=asd Commented Feb 17, 2013 at 18:29

2 Answers 2

3

If you are asking about how to make an HTTP request from PHP and get the response as a string, for the simplest cases you can use file_get_contents:

$html = file_get_contents('http://www.google.com');

If you want to do something more configurable then you have to go with curl.

Sign up to request clarification or add additional context in comments.

2 Comments

This is exactly what I was looking for thank you. On to figuring out the next step! Also, looking into curl to see if that's more of what I need. Thank you sir.
@JuJoDi, if this answer was what you're looking for, please mark as best answer.
0

Do you want to prevent sending the source to the visitor's browser and get it as a string instead? You can use output buffer.

Put this line at the beginning of your code:

ob_start();

From now on everything that would normally be sent to the browser will be buffered instead. To end buffering and get contents use:

$out = ob_get_contents();    // this will only get the contents
$out = ob_get_clean();       // this will also empty the buffer

To stop buffering:

ob_end_clean();              // will just stop buffering
ob_end_flush();              // will also echo() current buffer

Output buffer docs here.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.