PHP read the file _2014.5.26 summary

Source: Internet
Author: User
Tags fread

1. PHP Partial file Operation function

(1) fopen Open File function

      fopen ( path and file name, open mode );

(2) fread Read file contents

      fread ( open file, end position );

(3) filesize Read file size, bytes in units of measure

      filesize ( path and file name );

(4) fwrite Write file contents

      fwrite ( path and file name, write content );

(5) fclose Close Open File

Close ( path and file name );

  

Cases:

<?php

$arr = Array ("News title 222", "News Content 222"), Array ("News title 333", "News content 3333"));

foreach ($arr as $id = = $value) {

$fp = fopen ("tmp.htm", "R");

str = fread ($fp, FileSize ("tmp.htm"));

Fclose ($FP);

$title = $value [0];

$content = $value [1];

$path = $id. ". HTML ";

$str = Str_replace ("{title}", $title, $STR);

$str = Str_replace ("{content}", $content, $STR);

$NFP = fopen ($path, "w");

Fwrite ($NFP, $STR);

Fclose ($NFP);

}

? >

2,unlink () rmdir () Delete function

Unlink () Delete file function

Unlink (path and file name)

RmDir () Delete a directory function

RmDir (path and directory name)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.