cURL和PHP:停止输出到屏幕 [英] cURL and PHP: Stop output to screen
本文介绍了cURL和PHP:停止输出到屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此PHP脚本将减去XML的所有数据打印到浏览器(我使用的是Chrome)。我该如何抑制输出到屏幕?
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>
推荐答案
您忽略了 F
在 TRANSFER
中进行更改:
You ommitted the F
in TRANSFER
, change this:
curl_setopt($ ch ,CURLOPT_RETURNTRANSER,1);
为此:CURLOPT_RETURNTRANS F ER
To this: CURLOPT_RETURNTRANS F ER
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
这篇关于cURL和PHP:停止输出到屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文