I am trying to do system("cat variables.php&q开发者_StackOverflow社区uot;);
from a PHP script, but it doesn't write anything.
What's the problem?
If you want to display the entire file to users, try:
highlight_file("path/to/file");
http://us3.php.net/highlight_file
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 richer and more configurable.
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.
It's not clear what you are trying to achieve, but if you are trying to step through your PHP code, use:
- http://xdebug.org/
- http://www.firephp.org/
These tools will allow you to view your variables at different points in time.
In case anyone out there still needs the answer, put this anywhere in your code and it will display it with syntax highlighting.
show_source();
It should definitely work in PHP 5.0 and above.
精彩评论