Forum Moderators: coopster

Message Too Old, No Replies

Reading/Writing .php files

reading and writing php files

         

xKillswitchx

6:40 am on Jan 6, 2008 (gmt 0)

10+ Year Member



I have run into a small issue. I know how to read and write from text files and many other files, but not php files. I cant read the contents of a PHP file, because I am assuming, the file is executed server side first?

I want to have a small form to be able to edit values of the PHP file like how you can in Joomla and other CMS/forum scripts.

Any assistance in reading from PHP files with PHP?

mikesmith76

10:21 am on Jan 6, 2008 (gmt 0)

10+ Year Member



You should be able to read a php file like you would any other text file. What have you tried so far?

Birdman

5:21 pm on Jan 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you should be able to:

$filecontents = file_get_contents( 'file.php' )
$filecontents = str_replace( '[TOKEN]', 'New Text', $filecontents );
$handle = fopen( 'file.php', 'w' );
fwrite( $handle, $filecontents );
fclose( $handle );
exit;

xKillswitchx

7:18 pm on Jan 6, 2008 (gmt 0)

10+ Year Member



Sorry, it seems that I can't just echo the php data to view it, I have to append htmlspecialchars( $data ) to view it properly :D Thanks.