PHP method for getting the number of file lines, _ PHP Tutorial

Source: Internet
Author: User
PHP method for obtaining the number of file lines ,. The PHP method for getting the number of file lines. this example describes how PHP can get the number of file lines. Share it with you for your reference. The specific analysis is as follows: two implementation methods are provided, although the second PHP method obtains the number of file lines,

This example describes how to obtain the number of objects in PHP. Share it with you for your reference. The specific analysis is as follows:

Two implementation methods are provided. although the second method is easy to understand, the first method is the best.

First:

<? Php $ file_path = 'xxx.txt '; // file path $ line = 0; // Number of initialization rows // open the file $ fp = fopen ($ file_path, 'r ') or die ("open file failure! "); If ($ fp) {// get the content of a row of the file. note: php5 is required to support this function. while (stream_get_line ($ fp, 8192, "\ n") {$ line ++;} fclose ($ fp); // close the file} // Number of output rows; echo $ line;?>

Second:

<? Php $ line = count (file ('filename'); echo $ line;?>

The second method is inefficient because you want to save the file content.

I hope this article will help you with php programming.

Example: This article describes how to obtain the number of objects in PHP. Share it with you for your reference. The specific analysis is as follows: two implementation methods are provided, although the second...

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.