How can I display php source code

I am trying to make a system ("cat variables.php"); from a PHP script, but it doesn’t write anything :( Does anyone know what the problem is?

+3
source share
5 answers

If you want to display the entire file for users, try:

highlight_file("path/to/file");

http://us3.php.net/highlight_file

+8
source

You can use to get the contents of the file. file_get_contents

And you can use to get the path to the current file - if you want the current file of course __FILE__


So, to display the contents of the current file:

echo file_get_contents(__FILE__);

Note 1: you may need some shielding:

echo '<pre>' . htmlspecialchars(file_get_contents(__FILE__)) . '</pre>';

2: , - , :

echo '<pre>' . htmlspecialchars(file_get_contents('/path/to/my/file.php')) . '</pre>';


, - - highlight_file; - GeSHi, .

+4

, PHP phps. .

0

In case someone else needs an answer, put it somewhere in your code and it will display it with syntax highlighting.

show_source();

It should definitely work in PHP 5.0 and above.

0
source

Source: https://habr.com/ru/post/1739488/


All Articles