PHP Curl prints extra character -
i m using code print contents of page (also pass post
, cookie
). gives "1
" @ end of content.
php code
function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); $fields = array( ); $fields_string = ''; $post_count =0; foreach($_post $key=>$value){ $fields_string .= $key.'='.$value.'&'; } $fields_string .= 'fb_app=1'; curl_setopt($ch,curlopt_post, count($_post)+1 ); curl_setopt($ch, curlopt_postfields, $fields_string ); $cookie_string=""; foreach( $_cookie $key => $value ) $cookie_string .= "$key=$value;"; curl_setopt($ch,curlopt_cookie, $cookie_string); $data = curl_exec($ch); curl_close($ch); return $data; } echo file_get_contents_curl('http://example.com/my_page/');
output
<!doctype html> <html lang="en"> <head> </head> <body> <p>hello world.</p> </body> </html> 1
from http://us2.php.net/curl_exec
returns true on success or false on failure. however, if curlopt_returntransfer option set, return result on success, false on failure.
so need set curlopt_returntransfer
return html (instead of true, prints 1) curl_exec
curl_setopt($ch, curlopt_returntransfer, true);
Comments
Post a Comment