Jump to content


Photo

Aew Me Ajuda No Sistema De Busca!


  • Faça o login para participar
8 replies to this topic

#1 y3k

y3k

    Novato no fórum

  • Usuários
  • 14 posts
  • Sexo:Não informado

Posted 25/09/2004, 18:33

Ta aew o codigo espero que alguem saiba me ajudar, to querendo que o sistema faça a busca em mais de um arquivo, tipow ele faz a busca no arquivo site.txt eu quero q ele faça a busca em 4 arquivo... site.txt , site2.txt , site3.txt e site4.txt :( alguem pode me ajudar? :) muito grato valeu aew! ;) meu email é juniormartins#brazil.com tks! ;)

esse é o arquivo buscar.php :) :unsure:

<?
if($action == "buscar") {

include "config.php";
$filename = "db/site.txt";

if(strlen($keyword) <= 3){
print "<p><b>A palavra deve ter no mínimo 3 letras</b><br>";
}
else{

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}


$user = file("$filename");
$searching = count($user);
$lis = 0;
for($x=0;$x<sizeof($user);$x++) {
$temp = explode("|",$user[$x]);
$line[$x] = "$temp[0]";

$keyword = trim($keyword, " ");
$keywords = explode(" ", $keyword);


foreach ($keywords as $word){
if(stristr($temp[0], $word) || stristr($temp[0], $word)) {
$collect[$lis] = $line[$x];
$lis++;
}
}
}

$time = microtime();
$time = number_format($time,3);

if($lis > 0){
$list = array_values(array_unique($collect));
}
else $list = $collect;
//var_dump($list);


if(sizeof($list) != "0") {

//sort($keyword);
echo "<p><b>",sizeof($list),"</b> Resultados da pesquisa para <b>$keyword</b></p></font>";

for($y=0;$y<sizeof($list);$y++) {
$temp = explode("|",$list[$y]);
echo '<div align="center">
<center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-bottom-width: 0" bordercolor="#CCCCCC" width="100%" id="AutoNumber1">
<tr>
<td width="100%" height="20" bgcolor="#EEEEEE" style="border-bottom-style: none; border-bottom-width: medium">
<font size="2" face="Arial">&nbsp;<img src="gfx/ico_seriais.gif" width="14" height="7">&nbsp;',$temp[0],'</font></td>
</tr>
</table>';
}
if($stats == true){
echo "<p>Foram pesquisadas <b> $searching </b> páginas | A pesquisa durou <b>$time</b> segundos.<br><br>";
}
}

else{
echo "<p>Nenhuma ocorrência para a palavra digitada<b>$keyword.<br> Por favor, tente novamente</b><br><br>";
if($stats == true){
echo "A pesquisa durou<b>$time</b>segundos.<br>";
}
}

?>
<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post">
<input type="text" name="keyword" size="40" maxlength="100">
<input type="submit" name="submit" value=" Buscar ">
<input type ="hidden" name="action" value ="buscar">
</form>
<?
}
}
else if(!$action || $action == ""){
?>
<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post">
<input type="text" name="keyword" size="40" maxlength="100">
<input type="submit" name="submit" value=" Buscar ">
<input type ="hidden" name="action" value ="buscar">
</form>
<?
}
?>
<center>
</center>

============================================
termino ;)
y3k®

#2 Felipe Pena

Felipe Pena

    O temor do Senhor é o princípio da sabedoria

  • Ex-Admins
  • 6441 posts
  • Sexo:Masculino

Posted 26/09/2004, 07:07

Um exemplo amigo:

PHP
<?
$file
= file("site.txt");
$palavra = "felipe"; //palavra que será buscada...

foreach ($file as $linha=>$conteudo) {
if (
eregi($palavra, $conteudo) ) {
   echo "Foi encontrado na linha ".$linha." do arquivo!";
}
}
?>

Felipe Pena
[...] ó terra, terra, terra; ouve a palavra do Senhor. — Jeremias 22:29

#3 Klaus

Klaus

    @ ubuntu jaunty

  • Ex-Admins
  • 7924 posts
  • Sexo:Masculino
  • Localidade:127.0.0.1

Posted 26/09/2004, 07:29

Uma dica... Tenta usar banco de dados para sistemas de buscas... Vai simplificar e muito o seu trabalho...

Dahora seu avatar... ;)
Klaus Paiva
Conheça também: Taperás

#4 y3k

y3k

    Novato no fórum

  • Usuários
  • 14 posts
  • Sexo:Não informado

Posted 26/09/2004, 11:59

esse avatar eu achei no miarroba.com carretos página 4...

mais minha dúvida é pra buscar em mais de um arquivo não so no arquivo site.txt e sim em 3 arquivo sako? ;)
y3k®

#5 Felipe Pena

Felipe Pena

    O temor do Senhor é o princípio da sabedoria

  • Ex-Admins
  • 6441 posts
  • Sexo:Masculino

Posted 26/09/2004, 12:19

Cadê a dificuldade??

PHP
<?

$palavra
= "felipe"; //palavra que será buscada...

//primeiro arquivo
$file = file("site.txt");
foreach (
$file as $linha=>$conteudo) {
if (
eregi($palavra, $conteudo) ) {
 echo
"Foi encontrado na linha ".$linha." do arquivo!";
}
}

//segundo
$file2 = file("site2.txt");

foreach (
$file2 as $linha2=>$conteudo2) {
if (
eregi($palavra2, $conteudo2) ) {
 echo
"Foi encontrado na linha ".$linha2." do arquivo!";
}
}

//terceiro
$file3 = file("site3.txt");

foreach (
$file3 as $linha3=>$conteudo3) {
if (
eregi($palavra3, $conteudo3) ) {
 echo
"Foi encontrado na linha ".$linha3." do arquivo!";
}
}
?>

Felipe Pena
[...] ó terra, terra, terra; ouve a palavra do Senhor. — Jeremias 22:29

#6 y3k

y3k

    Novato no fórum

  • Usuários
  • 14 posts
  • Sexo:Não informado

Posted 26/09/2004, 12:21

valeu aew :P
y3k®

#7 y3k

y3k

    Novato no fórum

  • Usuários
  • 14 posts
  • Sexo:Não informado

Posted 26/09/2004, 13:22

mais eu queria que você modificae no meu script n no seu... :/
y3k®

#8 y3k

y3k

    Novato no fórum

  • Usuários
  • 14 posts
  • Sexo:Não informado

Posted 26/09/2004, 13:29

Por favo alguma alma caridosa poderia fazer essa modificasão pra buscar em mais de um arquivo nesse script?
PHP

<?
if($action == "buscar") {

include
"config.php";
$filename = "db/site.txt";

if(
strlen($keyword) <= 3){
print
"<p><b>A palavra deve ter no mínimo 3 letras</b><br>";
}
else{

function
getmicrotime(){
list(
$usec, $sec) = explode(" ",microtime());
return ((float)
$usec + (float)$sec);
}


$user = file("$filename");
$searching = count($user);
$lis = 0;
for(
$x=0;$x<sizeof($user);$x++) {
$temp = explode("|",$user[$x]);
$line[$x] = "$temp[0]";

$keyword = trim($keyword, " ");
$keywords = explode(" ", $keyword);


foreach (
$keywords as $word){
if(
stristr($temp[0], $word) || stristr($temp[0], $word)) {
$collect[$lis] = $line[$x];
$lis++;
}
}
}

$time = microtime();
$time = number_format($time,3);

if(
$lis > 0){
$list = array_values(array_unique($collect));
}
else
$list = $collect;
//var_dump($list);


if(sizeof($list) != "0") {

//sort($keyword);
echo "<p><b>",sizeof($list),"</b> Resultados da pesquisa para <b>$keyword</b></p></font>";

for(
$y=0;$y<sizeof($list);$y++) {
$temp = explode("|",$list[$y]);
echo
'<div align="center">
<center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-bottom-width: 0" bordercolor="#CCCCCC" width="100%" id="AutoNumber1">
<tr>
<td width="100%" height="20" bgcolor="#EEEEEE" style="border-bottom-style: none; border-bottom-width: medium">
<font size="2" face="Arial">&nbsp;<img src="gfx/ico_seriais.gif" width="14" height="7">&nbsp;'
,$temp[0],'</font></td>
</tr>
</table>'
;
}
if(
$stats == true){
echo
"<p>Foram pesquisadas <b> $searching </b> páginas | A pesquisa durou <b>$time</b> segundos.<br><br>";
}
}

else{
echo
"<p>Nenhuma ocorrência para a palavra digitada<b>$keyword.<br> Por favor, tente novamente</b><br><br>";
if(
$stats == true){
echo
"A pesquisa durou<b>$time</b>segundos.<br>";
}
}

?>
<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post">
<input type="text" name="keyword" size="40" maxlength="100">
<input type="submit" name="submit" value=" Buscar ">
<input type ="hidden" name="action" value ="buscar">
</form>
<?
}
}
else if(!
$action || $action == ""){
?>
<form action="<? echo ($_SERVER['PHP_SELF']); ?>" method="post">
<input type="text" name="keyword" size="40" maxlength="100">
<input type="submit" name="submit" value=" Buscar ">
<input type ="hidden" name="action" value ="buscar">
</form>
<?
}
?>

y3k®

#9 kenshinhimura

kenshinhimura

    Turista

  • Usuários
  • 40 posts
  • Sexo:Não informado

Posted 26/09/2004, 13:58

Como a gente pode transportar este script pra Mysql?




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq