homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

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

Msg#: 4110767 posted 2:19 pm on Apr 6, 2010 (gmt 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 :)



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

Msg#: 4110767 posted 6:21 pm on Apr 6, 2010 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved