Sharp Tutorial
File Handling in php

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

PHP Introduction

  • PHP home
  • PHP introduction
  • How to install and run
  • Syntax and Rule in PHP
  • Data type and operator
  • If else in php
  • Loop in php
  • Array in php
  • Sring in php
  • Function in php
  • Include in php

Working with Forms

  • Get and Post
  • Get Form input into PHP
  • Form Validation

PHP with MySQl

  • Connect PHP & Mysql
  • Insert using PHP Mysql
  • Select using PHP MySql
  • Delete Update using PHP Mysql
  • Login Page Example in PHP

Advanced PHP

  • Session in PHP
  • Cookies in PHP
  • File Handling in PHP
  • File Upload/Download PH

Object Oriented PHP

  • Class Obejct in PHP
  • Constructor in PHP
  • Destructor in PHP
  • Inheritance in PHP

File handling in php

Using PHP we can read data from the files or we can write the data into files for that we can open the file in different modes like read, write etc.

Syntax to open a file in php

<?php
  $f1=fopen("file-name","open-mode(r,w)");
?>

 

The content of the file may also be printed by using a single command.

<?php
  echo readfile("class-object.php");
?>

 

To read the content of a file line by line

<?php
$myfile = fopen("class-object.php", "r") or die("Unable to open file!");
// Output one line until end-of-file
while(!feof($myfile)) {
  echo fgets($myfile) . "<br>";
    // echo fgetc($myfile); to read character by character of the file
 
}
fclose($myfile);
?>  

 

Output of the above program display the content of the file as follows

Write the content into a file using php

<?php
$myfile = fopen("class-object.php", "r") or die("Unable to open file!");
// Output one line until end-of-file
while(!feof($myfile)) {
  echo fgets($myfile) . "<br>";
    // echo fgetc($myfile); to read character by character of the file
 
}
fclose($myfile);
?>  

 

Above program write the given content into the given file.

Enquiry about Course

Ask your Question

Click Here

Sharp (2) Tutorials

Video/ C Introduction

Watch video in full size

Video tutorial

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial