Welcome to WebmasterWorld Guest from 126.96.36.199 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Become a Pro Member
Reading/Writing .php files reading and writing php files xKillswitchx msg:3541456 6:40 am on Jan 6, 2008 (gmt 0) 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 msg:3541511 10:21 am on Jan 6, 2008 (gmt 0)
You should be able to read a php file like you would any other text file. What have you tried so far? Birdman msg:3541636 5:21 pm on Jan 6, 2008 (gmt 0)
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 msg:3541685 7:18 pm on Jan 6, 2008 (gmt 0)
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.