SunQuest
 
       PHP
  Home arrow PHP arrow Working With Text Files in PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Working With Text Files in PHP
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 76
    2002-12-18

    Table of Contents:
  • Working With Text Files in PHP
  • Opening and Reading Files
  • Creating and Writing Files
  • File Writing in Action
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    Working With Text Files in PHP


    (Page 1 of 5 )

    Sure, you know PHP's MySQL functions, but do you know how to read/write files in PHP? If not, then make sure you read this article. In it, Mitch teaches you everything you need to know to successfully work with files in PHP...We've come a long way since "back in the day" when it was the "in-thing" to work with flat-files to store application data. Back then (let's say early 1990's) it was popular to save records in CSV formatted plain text files, separated by new lines.

    In 1992 I was 10 and was happily plugging away in Microsoft QBasic, trying to build my first ASCII based game by saving high scores and level data into a plain-text file. It worked, but I wish MySQL was around back then!

    Today in late 2002, things are a lot different.

    Flat files are out and databases are in. I have worked with SQL Server, Access and Oracle, but talking as a software developer, I would have to say that MySQL is the mother of all databases. It's small. Fast. Sleek. Cross-platform. Easy to learn and gets the job done.

    I love databases, but I also think that every developer should at least have some basic knowledge of how to read and write files. You may be thinking "why would I need to use flat files. If I use files they're written in XML and I just use a parser to get what I want". Well, here are a couple of reasons why you might need to work with files:
    • To move binary data (such as image files) into a database as BLOBs (Binary Large Objects)
    • To import data (such as email addresses) that has been exported from a legacy database or application.
    • To export data out of a database into a text file so that it can be processed offline
    There are hundreds more reasons, many of which I'm sure you've already thought about. Anyway, today I want to run you through some basic file operations with PHP. File functions in PHP are very similar to those found in the C++ fstream library, so if you've come from a C++ background and haven't dabbled with files in PHP just yet, then you're in for an easy ride.

    More PHP Articles
    More By Mitchell Harper


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway