Home > 类库下载 > PHP类库 > body text

PHP reads a certain line of data from a large file text TEXT

高洛峰
Release: 2016-10-14 10:30:17
Original
1315 people have browsed it

function get_line($file,$line) {
    $fp = fopen($file,'r');
    $i = 0;
    while(!feof($fp)) {
        $i++;
        $c = fgets($fp);
        if($i==$line) {
            echo $c;
            break;
        }
    }
}
Copy after login
这个方式效率仍待考验
在一个apache的日志文件中(450M)
读取第20行非常之快 0.001039981842041
读取第200行0.0033199787139893
读取第2万行需要0.30908799171448 秒左右
读取第20万行2.5622429847717 seconds 已经到了无法忍受的地步
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template