cURL 和 PHP:停止输出到屏幕
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3435489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cURL and PHP: Stop output to screen
提问by Oso
This PHP script prints all the data minus the XML to the browser (I'm using Chrome). How can I suppress output to screen?
这个 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>
回答by Brandon Horsley
You ommitted the F
in TRANSFER
, change this:
你省略了F
in TRANSFER
,改变这个:
curl_setopt($ch,CURLOPT_RETURNTRANSER,1);
curl_setopt($ch,CURLOPT_RETURNTRANSER,1);
To this: CURLOPT_RETURNTRANS FER
对此: CURLOPT_RETURNTRANS FER
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);