共計 416 個字符,預計需要花費 2 分鐘才能閱讀完成。
在 PHP 中獲取外部網頁內容通常使用 cURL 庫或者 file_get_contents() 函數。下面分別介紹這兩種方法。
- 使用 cURL 庫:
$url = 'http://www.example.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
- 使用 file_get_contents() 函數:
$url = 'http://www.example.com';
$output = file_get_contents($url);
echo $output;
這兩種方法都可以用來獲取外部網頁的內容,但是 cURL 庫比 file_get_contents() 函數更強大和靈活,可以設置更多的選項和參數。
丸趣 TV 網 – 提供最優質的資源集合!
正文完