I am new to php, I need to read a text file’s 5th line and see if it contains a particular string
what would be the most efficient way to do it ?
I understand I can ready all lines using this method, should I put a counter here and break the loop if it is 5 ? or is there a better way to it ..
$file = fopen($fileName,'r');
while(!feof($file))
{
$name = fgets($file);
}
fclose($file);
EDIT
I have updated my code to this, but strpos always fails to find the string even if it is present..
I have verified the 5th line looks like this
PACKAGE_NAME: com.boom.appfree
//read entire file into an array
$lines = file($target_path);
//check line 5 if it contains free
$pos = strpos($line[4], 'free');
if ($pos === false)
{
$subject = "Paid Log uploaded";
} else
{
$subject = "Log uploaded";
}
Any advise please..
$lines =file("filename.txt");Then you can get the fifth line:
$lines[4]and search it for the word you are looking for withstrpos.