溫馨提示×

PHP怎么獲取外部網頁內容

PHP
小億
115
2024-04-29 14:43:40
欄目: 編程語言

在PHP中獲取外部網頁內容通常使用cURL庫或者file_get_contents()函數。下面分別介紹這兩種方法。

  1. 使用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;
  1. 使用file_get_contents()函數:
$url = 'http://www.example.com';
$output = file_get_contents($url);

echo $output;

這兩種方法都可以用來獲取外部網頁的內容,但是cURL庫比file_get_contents()函數更強大和靈活,可以設置更多的選項和參數。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女