php - 如何在 PHP 中包含外部文件?

标签 php

我需要在 php 网页中包含一个文件(属于另一台服务器)。

更准确地说:让我们假设我有这个网页:http://www.example.com/mypage.html 当在浏览器中查看时,它显示: 世界你好!

我想包含以下内容(不是来源): 世界你好!

在我的 php 页面内(假设在 www.myexampleserver.com 上)。我该怎么办?

我尝试过: 包括“http://www.example.com/mypage.html”;

但是它不起作用。

我也希望能够做这样的事情。在我的 php 页面源上:

echo“我的其他页面包含“.SomeCodeThatIDontKnow。”仅此而已”;

并在浏览器中查看时显示: 我的其他页面包含 Hello World !这就是全部

感谢您的任何指示。

最佳答案

$otherpage = file_get_contents("http://www.example.com/mypage.html");
echo "My other page contains: " . $otherpage;

如果您希望“其他页面”仅包含文本,您可能还想使用 htmlentities确保没有 HTML 注入(inject)到您的页面中..

$otherpage = file_get_contents("http://www.example.com/mypage.html");
echo "My other page contains: " . htmlentities($otherpage);

关于php - 如何在 PHP 中包含外部文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4984981/

相关文章:

php - 查找最活跃的玩家(表中满足条件的条目数最多)

php - 检查页面是否在 PHP 中使用 SSL

php - 网站首页显示数据库高亮需要SQL

php - 如何使用 select 语句在 php 和 mysql 中获取最新的日期和时间

php - Mustache (PHP) 输出关联数组键

php - 将字符串分解为数组

php - 需要使用 Concrete5 中外部表单的 SHA512 加密整个表

php - MySQL 通过 PHP 函数的返回进行排序

php - 代码点火器 3 : where clause gives an ambiguous column error

php - MySQL语法错误,似乎无法弄清楚