包含文件的全部内容并回显
问题描述:
我需要回显包含文件的全部内容.我尝试了以下方法:
I need to echo entire content of included file. I have tried the below:
echo "<?php include ('http://www.example.com/script.php'); ?>";
echo "include (\"http://www.example.com/script.php\");";
但是都行不通吗? PHP支持吗?
But neither works? Does PHP support this?
答
只需:
include("http://www.mysite.com/script.php");
或者:
echo file_get_contents("http://www.mysite.com/script.php");
注意:
- 由于网络延迟或另一台服务器运行缓慢,这可能会使您的页面速度变慢.
- 这要求您安装PHP时必须打开
allow_url_fopen
.一些主机将其关闭. - 这不会为您提供PHP代码,而会为您提供HTML/文本输出.
- This may slow down your page due to network latency or if the other server is slow.
- This requires
allow_url_fopen
to be on for your PHP installation. Some hosts turn it off. - This will not give you the PHP code, it'll give you the HTML/text output.