I adapted your code to fit my needs (such as: I replaced the ordered list with a $count variable because I didn't want the indentation), however, I have 3 Questions.
1) I am not real familar to patern matching etc. In the code you gave me, is it restrictive in any way? What I mean is that for some searches I get less results than I dowith using the stristr as I did earlier.
2) In my first echo line, I want to display the month, year and date associated with that record. I tried this:
but it prints December 31 for every enrty. The year is correct though. What did I do wrong?
3) I want to restrict the search results to a number, say, 200. I play around with:
but that returns no values. How did I screw that up?
Here is a snippet of the complete code:
PHP Code:
$file = file('data.txt');
$keys = preg_split('/[\s,]+/', preg_replace('/(^\s+|\#|\/|\'|\"|\~|\^|\.|\+|\$|\s+$)/', '', $search) );
$count = 0;
if (sizeof($keys) > 5)
{
die("Please enter less keywords");
}
$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);
}
}
ksort($matches);
if (sizeof($matches) > 0)
{
printf('<p>%d match%s found.</p>', sizeof($matches), sizeof($matches) == 1 ? NULL : 'es');
foreach ($matches AS $year => $match)
{
$count++;
echo '<center><b><font face="Times New Roman" size=2px">' . $count. '--' . $month . ' ' . $day . ', ' . $year . '</font></b></center>';
echo '<font face="Times New Roman" size="2px">' . current($match) .'</font>';
echo "<p>";
}
}
else
{
echo "No results were found for your search--Please try again";
}