Jump to content

Matching lines containing words from txt file


Thurrock

Recommended Posts

Hi,

 

I am banging my head against the wall here trying to get this to work, I need to read each line of a txt file and then match lines containing one or two word keywords, this script matches letters but I seem to be running into a wall here trying to get it to work, my guess it is a simple solution?

 

$lines = file('uploads/file.txt');

foreach ($lines as $line_num => $line) {
$line = strtolower($line);

if(preg_match("/version/i", "$line")){

echo "<span style=\"color:#cccccc;\">Line #<strong>{$line_num}</strong> : " . $line . "</span><br />\n";
}
else
{
echo "Line #<strong>{$line_num}</strong> : " . $line . "<br />\n";
}

}

 

Any help would be greatly appreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.