Welcome to WebmasterWorld Guest from

Forum Moderators: mack

Message Too Old, No Replies

Using text files to store data with PHP Templates

Is it possible to pull data from a text file and insert it into a template

2:19 pm on Apr 6, 2010 (gmt 0)

New User

5+ Year Member

joined:Apr 5, 2010
posts: 5
votes: 0

I'm looking for an alternative to MySql for storing data and wondering if using text files to store data is possible, and using PHP to extract the contents into a PHP/HTML template.


Links on a static page calls a PHP/HTML template and also a text file (unique to that link) with content which is then inserted into that template.

How possible would this be? Are there any online tutorials or books available ?

Thanks so much in advance :)
6:21 pm on Apr 6, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
votes: 0

Welcome aboard moonroot, it's absolutely possible and is often referred to as a "flat text database." That alone may lead to resources and even (old!) scripts that do this. I have heard via posts along the years that this site, in fact, functions on plain text files.

Instead of field names, you have to create your own row sets and delimiters, for example, using pipes,


. You have to do all the grunt work that mySQL does for you though. Manage carriage returns, split lines into arrays, searching the data becomes tedious and more difficult to implement, deleting/updating rows is more work, insuring proper file locking to avoid corruption, you need to write your own functions to generate "auto_increment" numbers and manage relational data, there are a whole list of challenges.

Another "tricky" one, in my example above, the end or a row of data is determined by the newline/carriage return. You have to implement a way to manage any newlines that may exist within the data for both storing and extracting so that it doesn't "end" the row mid-stream.

The two biggest downsides are that the data becomes exceptionally large in comparison to database engines and constantly opening and closing large text files can be hard on a server's hard disk. This many not be as true today as it was in the 90's, but it's still an issue.