Jump to content

Archived

This topic is now archived and is closed to further replies.

filo

Generate new php document

Recommended Posts

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 :)

 

Share this post


Link to post
Share on other sites

 

 

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".

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.