homepage Welcome to WebmasterWorld Guest from 54.205.193.39
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved