Page 1 of 1
PHP code (Search site without a database?)
Posted: Fri May 26, 2006 11:42 pm
by sabarna
I want to add Advanced search in PHP without using MSSQL for my website. please help me...
Posted: Sat May 27, 2006 12:04 am
by RobertGonzalez
Your post is insanely vague. Can you elaborate a little bit more? Make sure to mention specifically what you are looking to accomplish and what you need help with.
Posted: Sat May 27, 2006 2:40 am
by sabarna
Thanks for the reply. I want to have a Advanced search page for my website which will search whatever the viewer want to search from my site. I have created HTML form for that page. But don't know what to do next. Is there any process which doesnot include MSSQL? Please help me.....
Posted: Sat May 27, 2006 3:09 am
by RobertGonzalez
You want a user to be able to search flat content that is in the files on your server? Or are you using a database other than MSSQL?
Posted: Sat May 27, 2006 3:12 am
by sabarna
Thanks. Yes, I want a user to be able to search flat content that is in the files on my server. I am not using any database.
Posted: Sat May 27, 2006 3:36 am
by RobertGonzalez
You want
the PHP Filesystem functions. I will warn you now, this will be a slow way of doing things. You are literally going to have to open every file in every folder that you have, read each file into an array (or something like that), then match each line of each file against the user supplied search criteria term by term.
Posted: Sat May 27, 2006 3:41 am
by onion2k
I wouldn't bother searching the files themselves .. that would be incredibly slow, and very difficult to actually code.
Have you considered using Google?
http://www.google.com/searchcode.html allows you to embed a search box in your website that uses Google's index of the pages on your domain to search for things.
Posted: Sat May 27, 2006 3:43 am
by Chris Corbyn
sabarna wrote:Thanks. Yes, I want a user to be able to search flat content that is in the files on my server. I am not using any database.
Nowhere near as straightforward as using a database but if you have linux then rock on cos you could use my all time favourite linux tool - GREP!
Code: Select all
function search_files($string)
{
$ret = array();
$string = "'".str_replace("'", "\\'", $string)."'";
$results = `grep -ri --include=*.php $string .`;
$lines = explode("\n", $results);
foreach ($lines as $l)
{
preg_match('@(.*?):\s+(.*)@', $l, $matches);
$ret[] = array('file' => $matches[1], 'extract' => $matches[2]);
}
return $ret;
}
Example:
Code: Select all
$results = search_files('sunshine');
print_r($results);
/*
Array (
0 => Array (
file => ./start.php,
extract => but we ended up spending 3 weeks in the sunshine before coming home
)
)
*/
It's not tested but that the idea I'd go with. A pure PHP approacj would invlove some tricky recursion and lots of file_get_contents() followed by strpos() calls.
Posted: Sat May 27, 2006 3:53 am
by Chris Corbyn
I've editted your thread title because "PHP Code" doesn't really tell us anything about what your question is
