Well, it was more of an example. Give this a try:
PHP Code:
<?php
$search = $_POST['search'];
if ($search)
{
$file = file('data.txt');
$keys = preg_split('/[\s,]+/', preg_replace('/([^a-z0-9\s])/i', '', trim($search) ) );
if (sizeof($keys) > 5)
{
die("Please enter less keywords");
}
else if (empty($keys[0]))
{
die("Please enter a valid keyword.");
}
$pattern = '/('. implode('|', $keys) .')/i';
$matches = array();
foreach ($file as $line => $data)
{
list($month, $day, $year, $info) = explode('|', trim($data) );
if (preg_match($pattern, $info))
{
$matches[$year][] = preg_replace($pattern, '<span style="color:red;">$1</span>', $info);
}
}
if (sizeof($matches) > 0)
{
ksort($matches);
printf('<p>%d match%s found.</p>', sizeof($matches), sizeof($matches) == 1 ? NULL : 'es');
echo '<ol>';
foreach ($matches AS $year => $match)
{
echo '<li><font face="Times New Roman" size="2px">'. $year .': '. current($match) .'</font></li>'. "\n";
}
echo '</ol>';
}
else
{
echo '<p>No matches found.</p>';
}
}
?>
<form action="" method="post">
<input type="text" name="search" />
<input type="submit" value="Search" />
</form>