views:

134

answers:

4

I am trying to do system("cat variables.php"); from a php script but it doesn't write anything :( Anybody knows whats the problem?

+4  A: 

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

highlight_file("path/to/file");

http://us3.php.net/highlight_file

Chacha102
Its a file on my server and I want to output the entire php source code in my browser.
Mehmet Tuncal
+1  A: 

You can use file_get_contents to get the content of a file.

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


So, to display the content of the current file :

echo file_get_contents(__FILE__);

Note 1 : you might have to do some escaping :

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

Note 2 : you can do that with any file, of course -- just make sure the path to the file is correct :

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


And if you want more than just display the content -- if you want syntax-highlighting -- you could use the highlight_file function ; or something like GeSHi, which is more rich and more configurable.

Pascal MARTIN
But that doesn't have syntax highlighting! So sad...
Chacha102
@Chacha : I thought about that after posting *(the idea proposed in the OP wasn't doing syntax-highlight either)* ; so I was editing when you posted your comment ^^
Pascal MARTIN
Ok +1 :P ` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `
Chacha102
A: 

Its not clear what you are trying to achieve, but if you are trying to step through your PHP code use:

These tools will allow you to view your variables at different points in time.

Christopher Altman
A: 

If you're trying to display the contents of the file in its entirety some servers are configured to display the source of PHP files with a file extensions of phps. It will also syntax highlight the file's contents when displaying it.

John Conde