Home | Help Forums | Web Design Tutorials | Free Swishmax Downloads | All Downloads

 

 

Company

Home

Nework Details

Tutorials

SWiSH 2

SWiSHMax

Flash MX

PHP & MySQL

HTML / JScript

Adobe Photoshop

Corel Draw

Gimp

Miscellaneous

Downloads

Templates

Plugins

Fonts

Wallpapers

Free Images

Scripts and Codes

Products

E-Books

SWiSH BB

SWiSH Templates

SWiSH-DB Newsletter
Subscribe to our newsletter : GO
  Partners / Affiliates

   Swish Templates
   SWiSH Climax
   GimpTalk
   Idea Designs
   Sposatoettore
   Try Acai Berry Diet
   Download Free Ringtones
   Swishzone

Manage your site with Flax Article Content Management System
Read/Write/Append text file in PHP, new simple header file included
Category : PHP / MySQL | Level : Beginner | Language : English
Ask Question | Read Comments | Post tutorial | Previous | Next

Web www.swish-db.com

Read : Read data from file into a variable
Write : Writing new file
Append : Add more data at the end of file

useing.php
------------

CODE

<?

  include "file_func.php";

  //create file
  write_file("test.txt","This is my initail text\n");

  //add more data ot the existing file
  append_file("test.txt","New text added\n");

  $data=read_file("test.txt");

   echo "Data in file : <b>$data</b>";
?>





Following file must be included wherever you wish to use following functions,
and must be in the current folder.

file_func.php
-----------------------

CODE

<?
   //File will be rewritten if already exists
   function write_file($filename,$newdata) {
          $f=fopen($filename,"w");
          fwrite($f,$newdata);
          fclose($f);  
   }

   function append_file($filename,$newdata) {
          $f=fopen($filename,"a");
          fwrite($f,$newdata);
          fclose($f);  
   }

   function read_file($filename) {
          $f=fopen($filename,"r");
          $data=fread($f,filesize($filename));
          fclose($f);  
          return $data;
   }
?>




All rights reserved - swish-db.com