單色彩虹的答案比較完整,但做到獲取結果只需要
$post = 'theCityCode=' . urlencode('杭州') . '&theUserID='; //post數據
$curl = curl_init();
$header[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36';
$post = 'theCityCode=' . urlencode('杭州') . '&theUserID='; //post數據
$curl = curl_init();
$header[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36';
2016-08-10
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //curl_opt_http_header包裝請求頭
curl_setopt($curl, CURLOPT_URL, 'http://ws.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather');
curl_setopt($curl, CURLOPT_URL, 'http://ws.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather');
2016-08-10
curl_setopt($curl, CURLOPT_HEADER, 0); //如果你想把一個頭包含在輸出中,設置這個選項為一個非零值。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //結果緩存,不直接輸出
curl_setopt($curl, CURLOPT_POST, 1); //設置為post請求,否則默認為get
curl_setopt($curl, CURLOPT_POSTFIELDS, $post); //post的數據
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //結果緩存,不直接輸出
curl_setopt($curl, CURLOPT_POST, 1); //設置為post請求,否則默認為get
curl_setopt($curl, CURLOPT_POSTFIELDS, $post); //post的數據
2016-08-10
$response = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string($response);
print_r($xml);
curl_close($curl);
$xml = simplexml_load_string($response);
print_r($xml);
2016-08-10
請求頭里需要偽裝成瀏覽器,
$header[] = 'User-Agent: xx';
$header[] = 'User-Agent: xx';
2016-08-10
這不是講PHP基礎,而是curl的運用。老師提出的完整的使用步驟,應用領域,以及注意重點,這就夠了。想要深入理解每個細節,可以去看官方文檔。如果老師去講那個函數,這課時間不知多長,而且沒有什么意思(又不是講基礎語法,函數)。
2016-08-02
在cmd實現php -i的前提就是在環境變量里添加,假如你的php安裝在d盤的www的目錄下:
path變量:D:\www\php54;D:\www\php54\ext;
path變量:D:\www\php54;D:\www\php54\ext;
2016-07-17