Programming Basics

  Home arrow Programming Basics arrow Page 4 - Working with text files
PROGRAMMING BASICS

Working with text files
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    2004-01-06

    Table of Contents:
  • Working with text files
  • Opening a text file
  • Writing data into a text file
  • Closing a text file
  • Reading from a text file
  • Deleting a file
  • Other functions regarding text files
  • An example
  • Advanced examples
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Working with text files - Closing a text file


    (Page 4 of 10 )

    When you've finished using the opened file, you must close it before you move on to new work. It is an easy function with one parameter to be passed, the file pointer which was used when opening the file.

    <?php
    fclose( $fp );
    ?>

    So, there is nothing much to talk about this function. We shall sum up the content we learnt to this point with the following example:

    <?php
    $inputString = "This is the first line.\nThis is the seconds line.\nThis is the third line.";

    $fp = fopen( "notes/data/names.txt" , "w" );
    fwrite( $fp, $inputString );

    fclose( $fp );
    ?>

    If you are not sure about something look here: http://us2.php.net/manual/en/function.fclose.php

    More Programming Basics Articles
    More By Codewalkers

    blog comments powered by Disqus

    PROGRAMMING BASICS ARTICLES

    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP
    - Calendar Construction with PHP
    - PHP`s Calendar Package
    - Getting Modified Versions and Correct Dates ...
    - Combining Date Functions in PHP
    - Using PHP for Date and Time in Programming
    - More Exception Handling with PHP
    - Exception Handling in PHP
    - Error Logging and Handling Exceptions
    - Configuration Directives for Error and Excep...
    - Error and Exception Handling
    - Python Modules for Games


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap