如何使用PHP在另一个网站上显示一个网站的内容?

发布于 2024-08-31 09:07:48 字数 131 浏览 3 评论 0原文

我正在尝试互相显示两个网站的内容,有人建议我使用 RSS 阅读器,但我的问题是:

除了使用 rss 之外,我还有什么可以尝试显示内容!?

我以为我可以连接到另一个网站的数据库,但这不起作用/

提前感谢

I'm trying to show contents of two websites in one another , someone suggest me to use RSS reader but my question is :

is there anything else i could try to show the contents , beside using rss !?

i thought i can connect to the database of another website , but that didnt work /

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄人书 2024-09-07 09:07:48

一些网络托管已禁用“读取文件”功能。但您可以使用“file_get_contents”功能。

$home = file_get_contents('example.com');
echo $home;

some of web hosting has disabled "readfile" function. But you can use "file_get_contents" function.

$home = file_get_contents('example.com');
echo $home;
静若繁花 2024-09-07 09:07:48

任何可以获取远程 URL 的 PHP 函数都可以帮助您。这可以很简单,

readfile('http://example.com'); // outputs contents of URL

如果您需要抓取 URL的某些内容或想要要对内容进行后处理,请考虑使用 DOM。如果您尝试解析特定的 XML 格式(如 RSS),请使用专门用于该格式的解析器。如果没有该格式的解析器,请使用 XSLT 对其进行转换到 HTML。

至于数据库访问,为什么不询问远程站点和数据库的所有者是否以及如何访问它。

就像您已经提出的问题下面的评论一样,如果您可以更具体地说明问题,我们就可以更具体地提供解决方案。

Any PHP function that can fetch remote URLs can help you with that. This can be as simple as doing

readfile('http://example.com'); // outputs contents of URL

If you need to scrape only some contents of a URL or want to postprocess the content, consider using DOM. In case you are trying to parse a specific XML format like RSS, use a parser specialized for that format. If there is no parser for that format, use XSLT to transform it to HTML.

As for database access, why not ask the owner of the remote site and database if and how you may access it.

Like the comments below your question already suggested, if you can be more specific about the problem, we can be more specific about a solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文