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 > 0 ? $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($template, 0, strpos($template, '<!--SearchResultsBegin-->'));
$file_template = substr($template, strpos($template, '<!--SearchResultsBegin-->') + 25, strpos($template, '<!--SearchResultsEnd-->')-(strpos($template, '<!--SearchResultsBegin-->') + 25));
$end_template = substr($template, strpos($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($content, strpos ($content, '<title>') + 7);
$title = substr($title, 0, strpos ($title, '</title>'));
/* Parse the content for search content */
$content = substr($content, strpos ($content, '<!--SearchAreaBegin-->') + 22);
$content = substr($content, 0, strpos ($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;
?>
Código PHP:
$files = opendir('.');
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