Jump to content

Generate new php document


filo

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

 

Link to comment
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".

Link to comment
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

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.