cURL和PHP:停止输出到屏幕

And*_*ndy 30 php xml twitter curl

这个PHP脚本将所有数据减去XML打印到浏览器(我使用的是Chrome).如何将输出抑制到屏幕?

<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>
Run Code Online (Sandbox Code Playgroud)

Bra*_*ley 54

你忽略,则FTRANSFER,更改此:

curl_setopt($ch,CURLOPT_RETURNTRANSER,1);

对此:CURLOPT_RETURNTRANS F ER

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

  • 奇怪的是你没有在错误显示或日志中得到"使用未定义的常量CURLOPT_RETURNTRANSER .."消息. (3认同)