I need to get a line position of file pointer from file like below.
string1\n
string2\n
string3\n
I’m reading file using this func.
function get() {
$fp = fopen('example.txt', 'r');
if (!$fp) {
echo 'Error' . PHP_EOL;
}
while(!feof($fp)) {
$string = trim(fgets($fp));
if(!$string) {
continue;
} else {
/*
* Here I want to get a line number in this file
*/
echo $string . PHP_EOL;
}
}
}
The simple solution is to use a counter.