37

This PHP script prints all the data minus the XML to the browser (I'm using Chrome). How can I suppress output to screen?

<html>
<head><title>Twitcap</title></head>
<body>
<?php
  function twitcap()
  {
    // Set your username and password
    $user = 'osoleve';
    $pass = '********';

    $ch = curl_init("https://twitter.com/statuses/friends_timeline.xml");

    curl_setopt($ch,CURLOPT_HEADER,0); // We want to see the header
    curl_setopt($ch,CURLOPT_TIMEOUT,30); // Set timeout to 30s
    curl_setopt($ch,CURLOPT_USERPWD,$user.':'.$pass); // Set uname/pass
    curl_setopt($ch,CURLOPT_RETURNTRANSER,1); // Do not send to screen

    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,1);

    $xml = new SimpleXMLElement( curl_exec($ch) );
    curl_close($ch);

    return $xml;
  }

  $content = twitcap();
  echo "Hello, world.<br /><br />";
?>
</body>
</html>
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Andy
  • 3,132
  • 4
  • 36
  • 68
  • 2
    You're going to need to switch to OAuth soon. Basic Auth is going away on August 16, 2010. – icktoofay Aug 08 '10 at 18:25
  • Oh man, that sucks. Thanks for the heads up!" – Andy Aug 08 '10 at 19:46
  • I love how much traffic this is getting, and the occasional upvote, five years later. I guess it's a pretty common typo. – Andy Feb 03 '16 at 20:54
  • had the same issue and this question helped. 9 years later and your question is still getting upvotes. ;) – James Juanjie Jul 24 '19 at 08:25
  • The year is 2020. This question still gets upvotes for some reason. Why is this particular issue so common? Is there a bad PHP tutorial out there we're all finding? – Andy Feb 03 '20 at 16:50

1 Answers1

65

You ommitted the F in TRANSFER, change this:

curl_setopt($ch,CURLOPT_RETURNTRANSER,1);

To this: CURLOPT_RETURNTRANS F ER

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Brandon Horsley
  • 7,956
  • 1
  • 29
  • 28
  • Yeah, that seemed to do the trick. Thanks a million, that was driving me crazy. – Andy Aug 08 '10 at 18:28
  • 3
    Strange that you didn't get a "Use of undefined constant CURLOPT_RETURNTRANSER.." message in your error display or log. – GZipp Aug 08 '10 at 18:49
  • even with curl_setopt($ch,CURLOPT_RETURNTRANSFER,0); I'm getting response. even without "echo". I do not want the response. How to stop it? – Siddhartha Mahato Apr 12 '22 at 20:29