我需要在 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/