Forum Moderators: coopster
date¦name¦e-mail¦IP¦comments
All I need is a snippet that will return a list of entries that match the keyword/s I submit...
I know: mysql bla bla bla... But I want to stick to flat files for this. Try as I might, I just can't understand how to do it.
Can someone point me to some on-topic tutorials or scripts? Tutorials would be best, since I'd like to actually learn how-to, rather than just copy&paste. But scripts are also OK if you do some reverse engineering.
Thanks so much for all the help you'll give me!
Laura
The below code will read the text file and search each entry that matches your keyword which will then be tokenized and written to arrays for each field.
$keyword = "test"; //whatever your keyword is
if (file_exists("db.txt")){
$fdata = file("db.txt");
$c = 0;
foreach($fdata as $fline){
if(strpos($fline, $keyword)){
$date[$c] = strtok($fline,"¦");
$name[$c] = strtok("¦");
$email[$c] = strtok("¦");
$ip[$c] = strtok("¦");
$comments[$c] = strtok("¦");
$c++;
}
}
}
if($c > 0){
echo $c." results found for ".$keyword."<br>";
for($i=0; $i<=$c; $i++){
echo $date[$i];
echo $name[$i];
echo $email[$i];
echo $ip[$i];
echo $comments[$i];
}
}else {
echo "No results found for ".$keyword;
}
Hope this helps.