Foros del Web » Programando para Internet » PHP »

Inconveniente de buscador...

Estas en el tema de Inconveniente de buscador... en el foro de PHP en Foros del Web. Saludos, tengo un buscador que lo que hace es buscar archivos html y php segun el texto a buscar. Osea, que no busca en la ...
  #1 (permalink)  
Antiguo 03/06/2008, 10:39
Avatar de OsSk4R  
Fecha de Ingreso: octubre-2006
Ubicación: $this->home
Mensajes: 824
Antigüedad: 17 años, 6 meses
Puntos: 74
Inconveniente de buscador...

Saludos, tengo un buscador que lo que hace es buscar archivos html y php segun el texto a buscar. Osea, que no busca en la bd.

Bueno...el inconveniente es que solo busca en el directorio raiz. A mi me gustaria que buscara en 3 carpetas exactamente.

Este es el código:
Código PHP:
<?php



function strong($text$content$long)
{
    
$begin strpos($text$_GET["q"]);
    
$end   $begin strlen($_GET["q"]);
    
    
$begin $long $begin_cut $begin-$long $begin_cut=0;
    
$end $long strlen($text) ? $end_cut $end $long $end_cut strlen($text);
    
    
$strong  htmlentities(substr($content$begin_cut$begin-$begin_cut));
    
$strong .= '<strong>' htmlentities(substr($content$begin$end-$begin)) . '</strong>';
    
$strong .= htmlentities(substr($content$end$end_cut-$end));
    
    
$end_cut strlen($text) ? $strong .= '...' $strong;
    
$begin_cut $strong='...' $strong $strong;
    
    return 
$strong;
}

/* Read the configuration file */
if (file_exists("search.ini.php")) {
    include(
"search.ini.php");
} else {
    die (
'Configuration file missing.');    
}

/* Read the template file */
if (!empty($template) and file_exists($template)) {
    
$template file_get_contents($template);
} else {
    die (
'Template file or file name missing.');    
}

/* Parse the template */
$begin_template substr($template0strpos($template'<!--SearchResultsBegin-->'));
$file_template  substr($templatestrpos($template'<!--SearchResultsBegin-->') + 25strpos($template'<!--SearchResultsEnd-->')-(strpos($template'<!--SearchResultsBegin-->') + 25));
$end_template   substr($templatestrpos($template'<!--SearchResultsEnd-->') + 23);

/* Check the GET variable */
if (isset($_GET["q"])) {

    
/* Clear any html tags from string */
    
$_GET["q"] = strip_tags($_GET["q"]);

    
/* Clear quotes */
    
$_GET["q"] = str_replace('"'''stripslashes($_GET["q"]));

    
/* Replace especial characters */
    
if (is_array($chars)) {
        
$_GET["q"] = str_replace(array_keys($chars), array_values($chars), strtolower($_GET["q"]));
    }

    
/* Set the variables */
    
$results    '';
    
$result     0;
    
$abstract_length = ($abstract_length strlen($_GET["q"])) / 2;
    
    
/* Read the directory */
    
$files opendir('.');
    while (
false != ($file=readdir($files))) {
        
        
/* Check if file is a html file */
        
if (eregi('(htm|html|php)$'$file)) {
            
            
/* Read the file content */
            
$content file_get_contents($file);
            
            
/* Obtain the documment title */
            
$title substr($contentstrpos ($content'<title>') + 7);
            
$title substr($title0strpos ($title'</title>'));
            
            
/* Parse the content for search content */
            
$content substr($contentstrpos ($content'<!--SearchAreaBegin-->') + 22);
            
$content substr($content0strpos ($content'<!--SearchAreaEnd-->'));
            
$content strip_tags($content);
            
$content html_entity_decode($content);
            if (
is_array($chars)) {
                
$text=str_replace(array_keys($chars), array_values($chars), strtolower($content));
            }
            
            
/* Search the string in the content */
            
if (ereg($_GET["q"], $text)) {
                
$replace['<!--FileTitle-->']    = $title;
                
$replace['<!--FileName-->']     = $file;
                
$replace['<!--FileAbstract-->'] = str_replace('\r\n'' 'strong($text$content$abstract_length));

                
$results .= str_replace(array_keys($replace), array_values($replace), $file_template);
                
$result++;
            }
        }
    }
    
    
/* Create a result message */
    
if ($result==0) {
        
$message $noResults;
    } else {
        eval(
"\$message = \"$yesResults\";");
    }
} else {
    
$message $noString;
}

/* Join the documment parts and send it to browser */
$results $begin_template $results $end_template;
$results str_replace('<!--Results-->'$message$results);

echo 
$results;
?>
Sino me equivoco, exactamente en la linea 62:
Código PHP:
 $files opendir('.'); 
Ahí es donde tengo que especificar la carpeta en la que quiero que me busque, intente poniendo solo una carpeta (/ejemplo), (ejemplo), (/ejemplo/), pero nada, no busca.
Por eso acudo a ustedes. Es correcto, es ahí donde tengo que especificar la carpeta??

Y aparte, como dije...¿para que me buscara en 3 carpetas?

Muchas gracias de antemano
  #2 (permalink)  
Antiguo 03/06/2008, 10:51
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Respuesta: Inconveniente de buscador...

Prueba asi
Código PHP:
$files opendir('dir''dir2'); 
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #3 (permalink)  
Antiguo 03/06/2008, 11:50
Avatar de OsSk4R  
Fecha de Ingreso: octubre-2006
Ubicación: $this->home
Mensajes: 824
Antigüedad: 17 años, 6 meses
Puntos: 74
Respuesta: Inconveniente de buscador...

Gracias por responder, pero no lo entiendo la verdad, acabo de hacer lo que me has dicho y... lo he dejado asi;

Código PHP:
$files opendir('extra'); 
Extra es la carpeta!! y sigue sin funcionar.

Y a la hora de introducir el nombre del archivo para que lo busque, me muestra un error:

Warning: file_get_contents(uso.html) [function.file-get-contents]: failed to open stream: No such file or directory in C:\Archivos de programa\www\search.php on line 102

Gracias de nuevo,

PD: Primero quiero solucionar ese problema y luego probar hacer que busque en varias carpetas.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:45.