Jump to content

[SOLVED] php search


ted_chou12

Recommended Posts

I am planning to try and build a member search sort of thing, so I need to know the general idea of it, in order to make my life easier later. So could anyone please explain to me how does php search work?
btw way, I dont use mysql and databases, so can there be a php search for text files in a directory? or search for words and phrases between the html tags?
However, what I am looking for is not javascript search, I have seen one of those before where you enter into the input box and it highlights the match string. NO, those are not what I am looking for.
Thank you
Ted.
Link to comment
https://forums.phpfreaks.com/topic/31223-solved-php-search/
Share on other sites

Wow you really know how to make things difficult. TEXT files!?!?! Well anyway the search for text files and database is basically the same concept. Before I post any code can you give me some info.

How many text files do you need to search through??
What format are the text files in?? can you give an example of them??
What do you want to return to the browser once it is found??

BTW we will have to get you a tent and a sleeping bag, You are here 24/7  ;D

Ray
Link to comment
https://forums.phpfreaks.com/topic/31223-solved-php-search/#findComment-144409
Share on other sites

hey, thanks ray. :D
I am still not quite sure about it as well, but i sort of have a general idea alreay, I have username, name, signupdate, birthday, profile,... (*you know, and many more others like those web communities.)
The format can be something like a brief intro, like maybe one or two matched string, and for every matched string. it has a table, profile pic. at the left, and member brief details on the right, (such as username, name birthday and others)
but I believe all the details could be added on later, the heart(core) of this script is a search page and a results page,
btw the txt file formats are something near as $username#$name#$birthday#... (# is what I use to separate my pieces of data).
Thanks, Ted.
Link to comment
https://forums.phpfreaks.com/topic/31223-solved-php-search/#findComment-144424
Share on other sites

I made this quick form and search together for you
[code]<?php
function filesearch($keyword, $filename){
$data = file($filename);
  foreach($data as $line){
    if(stristr($line, $keyword)){
    $row = explode("#", $line);
    return ($row);
    }
  }
}
if(!isset($_POST['search'])){
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=POST>";
echo "<input type=text name=keyword><br>";
echo "<input type=submit name=search value=Search><br>";
echo "</form>";
} else {
$filename = "users.txt";
$row = filesearch($_POST['keyword'], $filename);
if(!$row){
  echo "No results found";
  } else {
  echo $row[0]."---".$row[3];
  }
}
?>[/code]

ray
Link to comment
https://forums.phpfreaks.com/topic/31223-solved-php-search/#findComment-144487
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.