Home  >  Article  >  Backend Development  >  php loop to read file content

php loop to read file content

巴扎黑
巴扎黑Original
2016-11-21 14:32:082401browse

Every medium and large website will have a log. The log is stored in ***.log in the form of text. The log generally stores the operation overview of the website, basic information of the user, user usage habits and other information. Obviously, analyzing logs is an urgent matter, and logs can have tens of thousands or even hundreds of thousands of lines. How can such a large file be analyzed?

You can analyze each line by looping the log. The following is the code:

Php code

$txt_file = $savepath . '/report.log';  
$file_handler = fopen($txt_file, 'r');//以可读方式打开文件  
while (!feof($file_handler)) {  
    $con = fgets($file_handler);  
    //$con就是每一行的内容,在这里进行必要的分析  
}


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