使用file_get_contents

问题描述 投票:-2回答:5

我使用file_get_content窃取rss。

我尝试使用:

echo file_get_contents("http://vnexpress.net/gl/xa-hoi/2011/11/mot-so-bo-truong-the-hien-su-ne-tranh-trach-nhiem/");

结果是页面的内容

我尝试使用

echo file_get_content("http://hcm.24h.com.vn/ban-tre-cuoc-song/noi-doi-de-quyen-ru-chang-c64a418748.html"); 

结果为空白页。为什么我不明白?此页面不允许使用file_get_contents函数吗?对不起,我英语不好,请允许我的问题。谢谢

php file-get-contents
5个回答
4
投票

尝试使用file_get_contents代替file_get_content


3
投票

您缺少s。应该是

echo file_get_contents("http://hcm.24h.com.vn/ban-tre-cuoc-song/noi-doi-de-quyen-ru-chang-c64a418748.html");

1
投票

首先是file_get_contents,而不是file_get_contents。其次,它无法与http链接一起使用。

http://vnexpress.net/gl/xa-hoi/2011/11/mot-so-bo-truong-the-hien-su-ne-tranh-trach-nhiem/

应该是

/ home / 48564568 / public_html / gl / xa-hoi / 2011/11 / mot-so-bo-truong-the-hien-su-ne-tranh-trach-nhiem /

取决于您的服务器。

要找到链接应该是什么,请尝试添加一个不存在的文件,像这样

include(somethingrandom.php);

您将收到一条错误通知,指出/ the / path / you / need / somethingrandom.php不存在。


0
投票

PHP文档明确指出file_get_contents支持远程文件,但是您需要启用allow_url_fopen配置选项。如果未设置user_agent指令,许多站点(以我的经验)会避免传递内容。您还应该尝试将此值设置为有效的用户代理字符串。

来自https://www.php.net/manual/en/function.file-get-contents.php

示例#1获取并输出网站首页的来源

<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>

来自https://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

这里是配置指令的简短说明。

allow_url_fopen布尔值

此选项将启用URL感知的fopen包装器,可访问文件等URL对象。默认包装提供用于使用ftp或http访问远程文件协议,某些扩展(例如zlib)可能会注册其他包装器。

[可能有很多事情(超出此答案的范围)可能会阻止您提取文件,但我发现很多次,仅将user_agent指令设置为有效字符串即可解决问题。] >


-2
投票

首先是file_get_contents,而不是file_get_content。其次,它不能与http链接一起使用。http://truyen-cuoi.net/

© www.soinside.com 2019 - 2024. All rights reserved.