0

I have a php file like this.

Line   |   Length of Line
              1 2 3 4 5 6 7 8 9
1        |  < ? php
2        |
3        |                $g r a d e = 5;
4        |
5        |  ? >

How to count Total lines and Length of each line from this file in php?

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416

1 Answers1

0

This stack respond partially to your question: https://stackoverflow.com/a/13246630/6535806, just need in the while to get le length of the $line. So the code should look like:

$handle = fopen("filename.extention", "r");
// if the file exist
if ($handle) {
    // for each line
    while (($line = fgets($handle)) !== false) {
        // write the length of the line
        echo strlen($line).'<br />';
    }
    // then we close the file opened
    fclose($handle);
} else {
    // error opening the file.
}
Community
  • 1
  • 1