Edittable Template System (Like Wordpress)
Hey all, working on creating a template system for my own open source software. I want to make it completely edittable like a wordpress theme. I was wondering what the most efficient method is in terms of fwriting/fileputcontents and overall organization of how it's done?
I mean, I'm essentially taking a file say footer.php, fopen'ing it in a+ mode and putting all of it's content into a textarea. The user then edits it, and then I would clear the files contents, and write the textareas content to the same file. Then close that file.
Perhaps there's a better way of doing it, and that's my que开发者_JS百科stion :P.
Thanks.
I think it doesn't matter if you use: fopen, fwrite & fclose instead of file_put_contents (note that this is PHP5 only ;-) )
http://php.net/manual/en/function.file-put-contents.php
Note that this is only a shortcut, but I think it's better to use because your code will be cleaner.
The content of the file should you get with file_get_contents, because the fread() only gets 8192 bytes and than you must use a loop. (for more informations visit the docu. )
But here my version:
- file_get_contents('foo.bar'); // into a textarea
- retrive the new version
- and write the new file with file_put_contents(), the old one will be replaced.
Jeff Hubbard in Comment:
You should probably look into PHPTAL instead of trying to replicate the horribleness that is the WordPress template system. You'll thank me later.
精彩评论