Home > Backend Development > PHP Tutorial > 读取文件内容_PHP

读取文件内容_PHP

WBOY
Release: 2016-06-01 12:32:10
Original
881 people have browsed it



读取文件内容



 // 打开文件同时打印文件的每一个字符
 if($myFile = fopen("data.txt", "r"))
 {
 while(!feof($myFile))
 {
  $myCharacter = fgetc($myFile);
  print($myCharacter);
 }
 fclose($myFile);
 } 
?>
print("
");?>

 // 打开文件同时打印文件的每一行
 if($myFile = fopen("data.txt", "r"))
 {
  while(!feof($myFile))
  {
   $myLine = fgets($myFile, 255);
   print($myLine);
  }
 fclose($myFile);
 } 
?>
print("
");?>

 /* 打开文件同时打印文件的每一行,
 同时去掉取回字符串中的 HTML 语言
 */
 if($myFile = fopen("data.txt", "r"))
 {
  while(!feof($myFile))
  {
   $myLine = fgetss($myFile, 255);
   print($myLine);
  }
  fclose($myFile);
 } 
?>




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template