Frx*_*rem 84
你应该使用readfile():
readfile("/path/to/file");
Run Code Online (Sandbox Code Playgroud)
这将读取文件并通过一个命令将其发送到浏览器.这基本上与以下相同:
echo file_get_contents("/path/to/file");
Run Code Online (Sandbox Code Playgroud)
除了file_get_contents()可能导致脚本崩溃大文件,而readfile()不会.
Ric*_*haw 14
只需使用:
<?php
include("/path/to/file.html");
?>
Run Code Online (Sandbox Code Playgroud)
这也将回应它.这也有利于在文件中执行任何PHP,
如果您需要对内容执行任何操作,请使用file_get_contents(),
例如
<?php
$pagecontents = file_get_contents("/path/to/file.html");
echo str_replace("Banana", "Pineapple", $pagecontents);
?>
Run Code Online (Sandbox Code Playgroud)
这不会执行该文件中的代码,因此如果您希望这样做,请小心.
我通常使用:
include($_SERVER['DOCUMENT_ROOT']."/path/to/file/as/in/url.html");
Run Code Online (Sandbox Code Playgroud)
因为那时我可以在不破坏包含的情况下移动文件.
如果你想确保HTML文件不包含任何PHP代码并且不会以PHP形式执行,请不要使用include或require,简单地执行:
echo file_get_contents("/path/to/file.html");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
110786 次 |
| 最近记录: |