php loop to read file content

巴扎黑
Release: 2016-11-21 14:32:08
Original
2400 people have browsed it

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就是每一行的内容,在这里进行必要的分析  
}
Copy after login


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!