How PHP Gets the number of file rows

Source: Internet
Author: User
It seems that there are functions that directly fetch the number of file rows.

Can I count on a row by line?

Large File Direct sys ("wc-l filename") is not high efficiency

Reply content:

It seems that there are functions that directly fetch the number of file rows.

Can I count on a row by line?

Large File Direct sys ("wc-l filename") is not high efficiency

Small files directly $line = count(file('filename')) ;
Large files can be considered for SplFileObject processing.

A row count is slower when the number of rows is more, such as using fgets to read a line by default, and each row produces a function call overhead.

You can use Substr_count ($str, "\ n") to count the number of return characters.

Large files, you can read 1MB fragments each time, and then use Substr_count number of travel, and then add the results.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.