php输出当前文件内容,没有文件读取功能
我这里有一个有趣的任务..是否可以在没有文件读取功能的情况下读取当前文件内容? (没有 file_get_contents、fopen 等)
所以如果我有
<?
echo 'hi';
// function to output this file code
?>
php 文件的输出应该与代码相同(但没有文件读取功能)
I have an interesting task here.. is it possible to read the current file contents without file reading functions? (without file_get_contents, fopen etc.)
so if i have
<?
echo 'hi';
// function to output this file code
?>
the output of the php file should be same as the code (BUT without the file reading functions)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以配置 Apache 以将 PHP 文件作为格式化源代码提供:
这将使任何
.phps
文件作为源提供而不是执行。如果您希望提供特定文件,但仍可以作为实际 PHP 脚本执行,则可以创建指向该文件的符号链接,并为该符号链接指定 .phps 扩展名。You can configure Apache to serve up PHP files as formatted source code with:
This'd make any
.phps
files be served up as source instead of executed. If you want a particular file to be served up, but also still be executable as an actual PHP script, you can create a symlink to it, and give the symlink a .phps extension.您始终可以更改 apache/webserver 配置以将 php 文件作为文本提供(无需运行代码)。
You can always change your apache/webserver config to serve php files as text (without running the code).
不,这是不可能的。您将需要使用文件函数来打开文件并读取它。
如果您正在寻找代码的特定属性,您可以尝试使用反射 API: http://www.php.net/manual/en/book.reflection.php
如果你只是想显示代码,你可以使用highlight_file/highlight_string函数: http://www.php.net/manual/en/function.highlight-file .php
No, this is not possible. You will need to use file functions to open the file and read it.
If you are looking for specific properties of your code, you could try using the reflection API: http://www.php.net/manual/en/book.reflection.php
If you just want to display the code, you can use the highlight_file/highlight_string functions: http://www.php.net/manual/en/function.highlight-file.php