SplFileObject::eof()函数是PHP中的标准PHP库(SPL)的内置函数,可用于文件末尾。句法:
string SplFileObject::eof( void )
参数:该函数不接受任何参数。
返回值:成功返回TRUE。
以下示例程序旨在说明PHP中的SplFileObject::eof()函数。
注意:程序1已使用gfg.txt文件,其中包含以下数据。
GeeksforGeeks A Computer Science Portal for Geeks
程序1:
<?php 
  
// Creating SplFile Object 
$file = new SplFileObject(__FILE__); 
  
foreach ($file as $gfg => $line) { 
   if($file->eof() == true) 
        { echo "Yes Reached EOF"; 
        break; 
        } 
} 
?>输出:
Yes Reached EOF
程序2:
<?php  
   
// PHP program to use array to check  
// multiple files  
   
$GFG = array( 
    "/home/rajvir/Desktop/GeeksforGeeks/dummy.php", 
    "gfg.txt", 
    "mime.php"
    ); 
   
foreach ($GFG as &$file_name) {  
   
    // Create new SplFile Object  
    $file = new SplFileObject($file_name);  
    foreach($file as $gfg=>$lines){ 
    if($file->eof() == true) 
        echo "Yes Reached EOF" . "</br>";  
    }    
}  
?>
输出:
Yes Reached EOF Yes Reached EOF Yes Reached EOF
参考: http://php.net/manual/en/splfileobject.eof.php
相关用法
- PHP SplFileObject getMaxLineLen()用法及代码示例
- PHP SplFileObject fwrite()用法及代码示例
- PHP SplFileObject ftruncate()用法及代码示例
- PHP SplFileObject ftell()用法及代码示例
- PHP SplFileObject fgetc()用法及代码示例
- PHP SplFileObject fstat()用法及代码示例
- PHP SplFileObject setMaxLineLen()用法及代码示例
- PHP SplFileObject fgetss()用法及代码示例
- PHP SplFileObject flock()用法及代码示例
- PHP SplFileObject fread()用法及代码示例
- PHP SplFileObject fgets()用法及代码示例
- PHP SplFileObject rewind()用法及代码示例
- PHP SplFileObject seek()用法及代码示例
- PHP SplFileObject fputcsv()用法及代码示例
- PHP SplFileObject current( )用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | SplFileObject eof() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
