filo Posted October 7, 2013 Share Posted October 7, 2013 Hello I need to make a script for practice that generates new php document based on some text. i can't find anything by googleing, but the same thing does fake news portals like http://www.fakeawish.com/ So far i have this - user inputs names and selects which type of news he wants (selection from database), text generates and i have a variable. i know how to save this into a new file (fwrite, for example) but i dont know how can i put this text inside of a pre-designed php document? Ty Quote Link to comment https://forums.phpfreaks.com/topic/282786-generate-new-php-document/ Share on other sites More sharing options...
trq Posted October 7, 2013 Share Posted October 7, 2013 i know how to save this into a new file What makes you think that? Do you think when someone makes a new post on this forum a new php script is created? Of course not. I think your missing the point of "dynamic content". Quote Link to comment https://forums.phpfreaks.com/topic/282786-generate-new-php-document/#findComment-1452980 Share on other sites More sharing options...
filo Posted October 7, 2013 Author Share Posted October 7, 2013 So.. are you saying i should use database for that? in the meantime, i managed to think of solution for putting text inside of a html template.. (I just put BLABLA words inside template.php and with preg_replace changed them with my text and saved as a new file.. ) as for doing that with a db ill try to do it tomorrow Quote Link to comment https://forums.phpfreaks.com/topic/282786-generate-new-php-document/#findComment-1452993 Share on other sites More sharing options...
adoado Posted October 18, 2013 Share Posted October 18, 2013 There is nothing wrong with using a file to store data ("flat file" storage) as long as you know it's pitfalls, one of which is the lack of protection when written to by different threads (that is, PHP processes may read and write to the file at the same time, and this can cause contention issues). If this is not an issue, flat file storage might be a good option, but trq is suggesting a database because they excel at preventing this type of issue (see ACID compliance). Not all databases are ACID compliant, so when you pick one, make sure it supports concurrency control (such as MySQL, PostreSQL, etc). That method of inserting text in HTML is fine, too, as long as you are aware of when that pattern falls. It's actually a better system than directly printing variables in the HTML (because a tight coupling of logic and design means neither can flexibly change) but there are better alternatives still. A templating system such as Mustache or Smarty provide this support, as well as iterative loops, basic post-variable "rendering" options, etc. In this case, I'd suggest reading up on MySQL and PDO. Quote Link to comment https://forums.phpfreaks.com/topic/282786-generate-new-php-document/#findComment-1454386 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.