<?
header
("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Fecha en el pasado
$db=mysql_connect("localhost","root","pass");
mysql_select_db("tabla",$db);

$q=$_GET['palabra'];
$query=mysql_query("SELECT asunto FROM ejemplos");
while(
$row=mysql_fetch_assoc($query))
    if(
busqueda($q,$row)){
            echo 
highlight_query($q,$row['asunto'])."<br>";
            
#echo"<hr>";
        
}

function 
busqueda($q,$row){
        
$q=array_unique(explode(" ",$q));
        
$q=array_filter($q,"filtro");//Filtra espacios.
        
$q=array_map("igualar",$q);//Filtra espacios.
        
sort($q);
        
$row=array_filter($row,"filtro");//Filtra espacios.
        
$row=array_map("igualar",$row);//Filtra espacios.
    
        /***********
        $_aux=array_merge($q,$row);
        p_r($_aux);
        /***********/
    
        
if(en_array($q,$row)){
                
#echo"<b>Si hay coincidencias.</b><br />\n";
                
return true;
            }else{
                
#echo"<b>No existe coincidencias</b><br />\n";
                
return false;
            }
    }

function 
filtro($cad){
        if(
eregi("^ *$",$cad))return false;//No devolvemos el valor.
        
return true;//Sino, la devuelve tal cual.
    
}

function 
igualar($cad){
        return 
strtr(strtolower($cad),"áéíóúñ","aeioun");
    }

function 
p_r($var){
        echo
"<pre>";
        
print_r($var);
        echo
"</pre>";
    }

function 
en_array($aguja,$pajar){
        for(
$q=0;$q<=count($aguja)-1;$q++)
            foreach(
$pajar as $paja)
                if(
ereg($aguja[$q],$paja)){
                        
$aguja[$q]=true;
                    }else{
                        
$aguja[$q]=false;
                    }
        if(
array_sum($aguja)!=count($aguja))
                return 
false;
            else
                return 
true;
        
#p_r($aguja);
        #p_r($pajar);
        #echo array_sum($aguja);
    
}

function 
highlight_query($q,$cad){
        return 
$cad;
    }
?>