所以,例如我有两个文件,index.php和test.php,我想得到代码,而不是转换为html / text的代码,test.php的代码并将其粘贴到index.php当我在浏览器中打开index.php以查看浏览器中的代码时,代码不再将代码转换为html / text。我尝试过:
<?php
$handle=file_get_contents("test.php", "r");
echo $handle;
//returns nothing
var_dump($handle);
//returns string(240) "
print_r($handle);
//returns nothing
答案 0 :(得分:0)
代码是不可见的,因为它在&lt;?php?&gt;里面标签和浏览器不知道如何渲染它。
您的选择是:
A)
标题('Content-Type:text / plain');
echo $ handle;
b)中
echo htmlspecialchars($ handle);
答案 1 :(得分:0)
由于PHP以<?..?>
开头,因此浏览器通常会尝试将其解释为HTML标记,这会使内容消失和/或以相当混乱的方式显示。您需要将这些特殊字符编码为HTML实体,以使它们在HTML上下文中正确显示:
echo htmlspecialchars(file_get_contents('test.php'));
答案 2 :(得分:0)
使用htmlentities输出代码:
echo htmlentities($handle);