$value) { if (trim($value)!=""){ if ($sal !=""){ $sal.= "OR (1 ". checkAnd($value). ") "; // #campos# = '". trim($value). "' "; //$sal.= checkAnd($value); }else { $sal.= "AND (1 ".checkAnd($value). ") "; // #campos# = '". trim($value). "' "; //$sal.= checkAnd($value); } } } //} return $sal; } function checkAnd ($consulta){ $tmp=explode(" ",$consulta); foreach ($tmp as $key => $value) { //if (strpos($value, 'OR') === FALSE) { if(trim($value) != "") { $sal.= "AND #campos# like '% ". trim($value). "%' "; //} else { //echo "asdasd"; } } return $sal; } function checkComillas($consulta) { if (strpos($consulta, '"') !== "false"){ //sip, hay $cons=str_replace('"', '"¬',$consulta); //echo $cons . !"
"; $temp=explode("¬",$cons); //echo print_r($temp). "

"; $frase[1] = $temp[0].$temp[1]; $frase[2] = $temp[2].$temp[3]; $frase[3] = $temp[4].$temp[5]; $frase[4] = $temp[6].$temp[7]; $frase[5] = $temp[8].$temp[9]; $frase[6] = $temp[10].$temp[11]; $frase[7] = $temp[12].$temp[13]; $frase[8] = $temp[14].$temp[15]; $frase[9] = $temp[16].$temp[17]; $frase[10] = $temp[18].$temp[19]; foreach($frase as $key => $valor) { if (substr($valor, 0,1)!="\"") { //no tiene " al principio, necesito separar. $cons=str_replace("\"","¬\"",$valor); $tmp2=explode("¬",$cons); $ttal=count($frase); $frase[$ttal+1]=$tmp2[0]; $frase[$ttal+2]=$tmp2[1] .'"'; $frase[$key]=""; } } //limpio foreach ($frase as $key => $value){ if (empty($frase[$key])|| $frase[$key]=="\"") unset($frase[$key]); } $frase=array_merge($frase); return $frase; } else { return $consulta; } } //ciera func. function doSearch($consulta,$id_cat){ session_unregister("q"); //saco $q if (get_magic_quotes_gpc()==1) { $consulta = stripslashes($consulta); } $patt="/-(^ ){1,}/"; //hago el query //$q="select * from notas where titulo like '%$consulta%' or copete like '%$consulta%' or texto like '%$consulta%'"; $q = "select * from preguntas where 1 "; if ($id_cat!="") $q .= "AND capitulo = '$id_cat' "; //me fijo si hay OR. //me fijo si hay comillas. $subs = array_merge (checkComillas($consulta)); foreach ($subs as $key => $value){ if (trim($value) == "OR") { //es un OR suelto. modifico el q. //echo "OR $value"; if (strpos($value, '"') !== "false"){ $q .= "OR #campos# like '%".str_replace("\"","",$subs[$key+1])."%' "; $subs[$key+1]=""; } else { //al no tener comillas, separo por espacio, buscando algun OR. $q .= checkOR($value); } }else{ if(stristr($value, '"') !== FALSE) { if ($subs[$key]!=""){ $q .= "AND #campos# like '%".str_replace("\"","",$subs[$key])."%' "; } } else { //echo "lalallaaaaaaa"; //al no tener comillas, separo por espacio, buscando algun OR. $q .= checkOR($value); } } //echo $value; /*//resteo el negativo if (strpos($value, '"') === "false") { //hay un menos sin comillas . traigo . echo "lalalal"; $as=ereg ("-(^ ){1,}", $value,$as); print_r($as); } */ //echo "$key ---> $value
"; } //eckOr($subs); //guardo q if ($order!="") $q .= " ORDER BY $order "; $campos_a_buscar= array('titulo','subtitulo','texto'); foreach($campos_a_buscar as $valor) { $queryfin[]= str_replace("#campos#",$valor,$q); //echo $q; } session_register("queryfin"); return $queryfin; } function renombrartitul($titul) { $titul=ereg_replace("","a",$titul); $titul=ereg_replace("","e",$titul); $titul=ereg_replace("","i",$titul); $titul=ereg_replace("","o",$titul); $titul=ereg_replace("","u",$titul); $titul=ereg_replace("","A",$titul); $titul=ereg_replace("","E",$titul); $titul=ereg_replace("","I",$titul); $titul=ereg_replace("","O",$titul); $titul=ereg_replace("","U",$titul); $titul=ereg_replace("","N",$titul); $titul=ereg_replace("","n",$titul); return $titul; } function renombrarconsulta($consulta) { $consulta=ereg_replace("","á",$consulta); $consulta=ereg_replace("","é",$consulta); $consulta=ereg_replace("","í",$consulta); $consulta=ereg_replace("","ó",$consulta); $consulta=ereg_replace("","ú",$consulta); $consulta=ereg_replace("","Á",$consulta); $consulta=ereg_replace("","É",$consulta); $consulta=ereg_replace("","Í",$consulta); $consulta=ereg_replace("","Ó",$consulta); $consulta=ereg_replace("","Ú",$consulta); $consulta=ereg_replace("","Ñ",$consulta); $consulta=ereg_replace("","ñ",$consulta); return $consulta; } function my_inArray($needle, $haystack) { # this function allows wildcards in the array to be searched foreach ($haystack as $value) { if (true === fnmatch($value, $needle)) { return true; } } return false; } function sendmail($email,$asunto,$texto,$from){ $MP = "/usr/sbin/sendmail -t"; $fd = popen($MP,"w"); fputs($fd, "To: $email\n"); fputs($fd, "From: $from \n"); fputs($fd, "Subject: $asunto\n"); fputs($fd, "X-Mailer: PHP3\n"); fputs($fd, "Content-Type: text/html\n"); fputs($fd, "$texto.\n"); pclose($fd); } ?>