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>
The procedure to hide curl progress bar is to pass the -s or --silent option to the curl command: Open the terminal application on your Linux/Unix. Type the command (pass -s option to curl to hide progress bar): $ curl -s https://your-dot-com-domain-name-here/ > /tmp/output. html.
cURL is a PHP extension that allows you to use the URL syntax to receive and submit data. cURL makes it simple to connect between various websites and domains. Obtaining a copy of a website's material. Submission of forms automatically, authentication and cookie use.
curl_setopt( $curl , CURLOPT_POSTFIELDS, $json_string ); curl_setopt( $curl , CURLOPT_HTTPHEADER, array ( 'Content-Type:application/json' )); curl_setopt( $curl , CURLOPT_RETURNTRANSFER, true ); $data = curl_exec( $curl );
You can't. The only way this would work is if you use persistent cookies in your curl request. CURL can keep cookies itself. Assign a session ID to the cookie file (in curl) so subsequent requests get the same cookies.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With