View Single Post
  #10 (permalink)  
Old 08-21-06, 05:57 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Ah yeh, I guess cause you're not storing the date format as I expected, and also it didn't go through all matches in the array. 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();
    
$matchcount 0;
    
    foreach (
array_values($file) AS $data)
    {
        list(
$month$day$year$info) = explode('|'trim($data) );
      
        if (
preg_match($pattern$info))
        {
            
$matches[strtotime("$day $month $year")][] = preg_replace($pattern'<span style="color:red;">$1</span>'$info);
            
$matchcount++;
        }
    }
    
    
    
    if (
sizeof($matches) > 0)
    {
        
ksort($matches);
        
$count 0;

        
printf('<p>%d match%s found.</p>'$matchcount$matchcount == NULL 'es');
        echo 
'<ol>';
    
        foreach (
$matches AS $days => $event)
        {
            foreach (
$event AS $tip)
            {
                list(
$month$day$year) = explode('-'date('M-d-Y'$days) );
                
$count++;
                
                echo 
'<center><b><font face="Times New Roman" size=2px">' $count'--' $month  '&nbsp;' $day ',&nbsp;' $year '</font></b></center>';
                echo 
'<font face="Times New Roman" size="2px">' $tip .'</font>';
                
                if (
$count >= 2)
                {
                    break;
                }

            }    
            
            if (
$count >= 2)
            {
                break;
            }
        }
        
        echo 
'</ol>';
    }
    else
    {
        echo 
'<p>No matches found.</p>';
    }
}

?> 
<form action="" method="post">
    <input type="text" name="search" />
    <input type="submit" value="Search" />
</form>

Last edited by nico_swd; 08-21-06 at 06:31 AM.
Reply With Quote