如何在屏幕上显示php文件


How can I display php file to the screen

如何从这个php文件向屏幕显示php文件?所以php脚本应该显示自己的代码。条件-禁止使用文件和输入语句!!!

<?php
echo file_get_contents('you_php_file.php');
?>

或简称

<?php
echo file_get_contents(__FILE__);
?>

在此处阅读有关file_get_contents的更多信息,在此处阅读关于__FILE__的更多信息

使用highlight_file,这样您就可以以漂亮的颜色格式获得源代码。

highlight_file($file_name);

如果PHP正在加载,您可以简单地回显代码,尽管您必须转义(双)引号:

Echo'$testvar1='''butterfly''';$testvar2='''lephant''';';

或者,如果你真的想显示所有的代码,donCallisto的方法更好;-)

要让php文件显示自己的代码,可以这样做:

<?php
echo file_get_contents(__FILE__);
?>

获取另一个文件的内容

<?php
echo file_get_contents("other_file.php");
?>

使用:

echo htmlspecialchars(file_get_contents($file));

(否则,如果使用echo file_get_contents($file);您必须单击页面上的View>Source,才能查看内容,因为它们被放在<>