Article View: be.comp.programming
Article #15296Re: doorzoeken van tekst-files op trefwoorden via php
From: Staf Wagemakers
Date: Thu, 26 Oct 2000 20:43
Date: Thu, 26 Oct 2000 20:43
59 lines
2476 bytes
2476 bytes
In article <hEFJ5.1242$Yq.55073@afrodite.telenet-ops.be>, Johan wrote:
>Ik zou voor m'n site een soort van search-engine willen maken
>die tekst-files doorzoekt op een aantal opgegeven trefwoorden.
>Het enige wat ik tot op heden gevonden heb is de functie
>fpassthru, maar dit lijkt me niet echt bruikbaar. Kan iemand
>me op weg helpen ? Is dit wat performant ?
't toeval wil dat ik ook aan zoiets bezig ben... Beneden zie je mijn huidige
code het zoek in alle html bestanden in de huidige dir naar een string en
toont de bestanden waarin de string voorkomt.
Gebruik: bv http//127.0.0.1/zoek.php?str=iets
Mischien heb je hier iets aan...
groetjes,
--
Staf Wagemakers
email : staf@digibel.org
homepage : http://www.digibel.org/~staf
<HTML>
<HEAD>
<TITLE>Zoeken...</TITLE>
</HEAD>
<BODY>
<?
if ( $str=="" ) {
echo "Can't read \$str<BR>";
exit;
}
$found=0;
$dirp = opendir(".");
while (($file=readdir($dirp))!="") {
$type=filetype($file);
if (($type=="file")&&(strstr($file,"html"))) {;
$fp=fopen($file,"r");
if ($fp) {
while (($line=fgets($fp,255))) {
if (strstr($line,$str)) {
$found=1;
?>
<A HREF=<? echo "./$file" ?>><? echo "./$file" ?></A><BR>
<?
break;
}
}
fclose($fp);
}
}
}
if(!$found) {
echo "String not found<BR>";
}
?>
</BODY>
</HTML>
Technical Details
Message-ID:
<slrn8vh5j4.1ho.staf@freeware.sam.be>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!xfer13.netnews.com!netnews.com!fr.clara.net!small.fr.clara.net!skynet.be!poster!stafReferences:
<hEFJ5.1242$Yq.55073@afrodite.telenet-ops.be>Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit X-Google-Thread: fe833,bcd732fcb83d6b28 X-Google-Attributes: gidfe833,public X-Google-Thread: 107324,bcd732fcb83d6b28 X-Google-Attributes: gid107324,public X-Google-Thread: fcea4,bcd732fcb83d6b28 X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2000-10-26 13:43:04 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!xfer13.netnews.com!netnews.com!fr.clara.net!small.fr.clara.net!skynet.be!poster!staf From: staf@digibel.org (Staf Wagemakers) Newsgroups: be.comp.programming,nl.comp.programmeren,pandora.os.linux Subject: Re: doorzoeken van tekst-files op trefwoorden via php Date: 26 Oct 2000 20:43:03 GMT Organization: Debian GNU/Linux 2.2 (potato) Lines: 59 Message-ID: <slrn8vh5j4.1ho.staf@freeware.sam.be> References: <hEFJ5.1242$Yq.55073@afrodite.telenet-ops.be> NNTP-Posting-Host: free1825.powered-by.skynet.be X-Trace: news1.skynet.be 972592983 17999 62.4.135.33 (26 Oct 2000 20:43:03 GMT) X-Complaints-To: abuse@skynet.be NNTP-Posting-Date: 26 Oct 2000 20:43:03 GMT User-Agent: slrn/0.9.6.2 (Linux)