PHP-Read Text file contents

Source: Internet
Author: User

PHP three ways to read the contents of a file://************** the first way to read the ***************************** code is as follows: Header ("Content-type:text/html;charset =utf-8 ");//Tell PHP preprocessor to pass content UTF8 format to browserFile path   $file _path= "Text.txt";  //determine if there is a file  if (file_exists ($file _path)) { if ($fp =fopen ($file _ Path, "A +") { //read file   $conn =fread ($fp, FileSize ($file _path)),  //Replace string   $conn =str_replace ("RN", "<br/>", $conn);  echo $conn. " <br/> ";  }else{ echo" file cannot be opened ";  } }else{ echo" without this document ";  } fclose ($FP);   //******************* the second reading method ***************************   code is as follows: Header ("content-type:text/ Html;charset=utf-8 ");  //file path   $file _path=" Text.txt ";  $conn =file_get_contents ($file _path);  $ Conn=str_replace ("RN", "<br/>", file_get_contents ($file _path)),  echo $conn;  fclose ($fp);   //****************** the third reading method, the loop reads the *****************   code as follows: Header ("Content-type:text/html;charset =utf-8 ");  //file path   $file _path=" Text.txt ";  //determine if the file exists  if (file_exists ($file _path)) { // Determine if the file can be opened  if ($fp =fopen ($file _path, "A +") {  $buffer =1024; //side read to determine whether the end of the file &nBSP; $str = "";  while (!feof ($fp)) {  $str. =fread ($fp, $buffer);  } }else{ echo "file cannot be opened";  } }else{ echo "no this file";  } //replacement character   $str =str_replace ("RN", "<br>", $str);  echo $str;  fclose ($fp);  the function:  $arr =parse_ini_file ("Config.ini") that reads the INI configuration file;  //returns an array  echo $arr [' Host ']. <br/> ";  echo $arr [' username ']." <br/> ";  echo $arr [' Password ']." <br/> "; 

PHP-Read text file contents

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.