PHP--File read/write

Source: Internet
Author: User

-----024-file.php-----

1<! DOCTYPE html>234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">5<title> File Handling </title>67<body>89<pre>Ten<?PHP One     $f _zzz=Iconv(' Utf-8 ', ' gbk ', ' D:\a\res\txt\ compound surname Utf-8.txt '); A     $fp _zzz=fopen($f _zzz, ' R ');//open file, return file handle -     $arr _zzz=file($f _zzz);//file = array -     $str _zzz=file_get_contents($f _zzz);//File = = String the     $arr _temp=Explode(‘ ‘,Preg_replace(' #\s+# ', ',$str _zzz)); -     Var_dump($arr _temp); -     Echo fread($fp _zzz, +), "\ n";//read 100 bytes of a file -     Echo fgetc($fp _zzz), "\ n";//read one character +     Echo fgets($fp _zzz), "\ n";//read a row -     Echo FGETSS($fp _zzz), "\ n";//read a row, filter HTML PHP tags +     Var_dump(Fgetcsv($fp _zzz));Echo"\ n";//read a row, filter HTML PHP tags A     Echo Fpassthru($fp _zzz);Echo"\ n";//read the remaining files at     Echo ReadFile($f _zzz);//Read all Files -     fclose($fp _zzz); -?> -</pre> -</body> -

-----025-file_write.php-----

1<! DOCTYPE html>234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">5<title> Write Files </title>67<body>89<pre>Ten<?PHP One     $f _zzz=Iconv(' Utf-8 ', ' gbk ', ' D:\a\res\txt\php write file test. txt '); A     $fp _zzz=fopen($f _zzz, ' W '); -     file_put_contents($f _zzz, "to the poor Trinidad and the eyes \ n");//Write a string -     fwrite($fp _zzz, "The day depends on the mountain."); the     fwrite($fp _zzz, "Yellow River into the current \ n"); -     fputs($fp _zzz, "A higher level \ n"); -     Echo"Current file pointer position:",Ftell($fp _zzz), "\ n"; -     fseek($fp _zzz, 32);//move the file pointer to the beginning of the third line +     fwrite($fp _zzz, "to the Poor thousand"); -     fseek($fp _zzz,-9, seek_cur);//pointer moves forward one line +     fwrite($fp _zzz, "Long sighing to hide."); A     Rewind($fp _zzz); at     fwrite($fp _zzz, "The window contains the West ridge Snow"); -  -  -  -  -  in     fclose($fp _zzz); -     Echo"File content: \ n".file_get_contents($f _zzz); to?> +</pre> -</body> the

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.