This blog summarizes a plenty of programming tricks coming from Allen's practical project experiences, including PHP, C#, Java, Yii Framework, Lucene...
Tuesday, 3 April 2012
PHP Auto get web page using curl.
//$url is in its valid URL format
static function get_web_page($url) {
$curl = curl_init ();
curl_setopt ( $curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $curl, CURLOPT_ENCODING, "" );
curl_setopt ( $curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.7 (.NET CLR 3.5.30729)" );
curl_setopt($curl, CURLOPT_ENCODING, "utf-8");
curl_setopt ( $curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $curl, CURLOPT_POST, 1 );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($curl, CURLOPT_URL, $url);
$content = curl_exec ( $curl );
curl_close ( $curl );
return $content;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment