[英]file_get_content get the wrong web
我正在學習使用PHP- file_get_contents
網站內容,但是出了點問題。我想要的網站是“ http://www.jandan.net ”。
但是使用file_get_content()
,我從“ http://i.jandan.net ”獲取內容(這是電話頁面,它們是不同的頁面)。 user_agent
也不可用。
<?php
ini_set("user_agent","Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100301 Ubuntu/9.10 (karmic) Firefox/3.6");
$url = 'http://www.jandan.net/';
/*
$opt = array( 'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: Mozilla/5.0\n"
)
);
$context = stream_context_create($opt);
*/
$content = file_get_contents($url);
echo var_dump($content);
?>
您在$content = file_get_contents($url,);
逗號$content = file_get_contents($url,);
造成了問題。
-------------------------------------------------- ----------------------- ^
保持逗號將產生以下錯誤消息:
解析錯誤:語法錯誤,.....(文件夾路徑等)中出現意外的“)”
快速說明 :使用$url = 'http://i.jandan.net/';
也有效,顯示了內容。
嘗試這個:
<?php
ini_set("user_agent","Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100301 Ubuntu/9.10 (karmic) Firefox/3.6");
$url = 'http://www.jandan.net/';
/*
$opt = array( 'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: Mozilla/5.0\n"
)
);
$context = stream_context_create($opt);
*/
$content = file_get_contents($url);
echo var_dump($content);
// echo $content;
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.