我正在使用simple_html_dom(http://simplehtmldom.sourceforge.net)来解析HTML代码。我在我的本地WAMP服务器上构建了一个应用程序,当一切正常时,我将它上传到我的网站上,但是我的服务器崩溃了(与本地代码相同)。
我跟踪了这个库的这个问题:
$contents = file_get_contents($url, $use_include_path, $context, $offset);
我试图制作一个测试文件:
<?php
$content=file_get_contents('http://mysite.net');
var_dump($content);
?>
然而,这很好用
$content=file_get_contents('http://mysite.net/gaming/search.php?search_id=active_topics');
或只是$content=file_get_contents('http://mysite.net/gaming');
返回bool(false)
,表示文件不正确
一切都在我的WAMP服务器上运行,但在我的debian Apache服务器上,我明白了。 我想也许我的问题来自我的php.ini文件,但我不知道从哪里开始(allow_url_fopen都打开)
感谢您的帮助!
编辑:我尝试添加ini_set('display_errors',1);
现在我明白了:
Warning: file_get_contents(http://mysite.net/gaming): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /web/*******
可能是因为URL重写或其他什么? (即使它在本地服务器x上工作))
答案 0 :(得分:-1)
取决于您使用的PHP版本,测试以下代码并查看哪些语句有效。
<?php
// <= PHP 5
$file = file_get_contents('./people.txt', true);
// > PHP 5
$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);
?>