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

读取文件内容_PHP

WBOY
WBOYOriginal
2016-06-01 12:32:10900browse



读取文件内容



 // 打开文件同时打印文件的每一个字符
 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);
 } 
?>




Statement:
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