search website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wood1e
Forum Newbie
Posts: 7
Joined: Tue Oct 05, 2004 11:39 am

search website

Post by wood1e »

Hi,

I am looking for a search option on my website...Looking through the internet I have found, Full-Text searching using PHP, on various websites.

I was just wondering if this is a good way to allow people to search, or is it now old hat, and there is a better way to have a search facility on my website?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Strictly speaking, FULL TEXT searching is a MySQL construct, not PHP. It is, nonetheless, the easiest way I've found, to search a website, and give those cool 'relevance percentage' figures.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
kickmaster
Forum Newbie
Posts: 6
Joined: Sun Jun 05, 2005 11:23 am

???

Post by kickmaster »

i wrote a search engine that works like this:

Code: Select all

<form action=&quote;&quote; method=&quote;get&quote;>
						    <div align=&quote;right&quote;>
						      <p>
						      <input type=&quote;text&quote; name=&quote;find&quote;>
						      <br>
                              <input type=&quote;submit&quote;  value=&quote;&#1513;&#1500;&#1495; &quote;name=&quote;ok&quote;>
						      </p>
						      <p>
						        <?
						  global $text;
						  $str=$_GET&#1111;&quote;find&quote;];
						  $l=strlen($str);
						  if((substr($str,1,1)==&quote;&quote;) and (substr($str,$l-1,1)==&quote;&quote;))
						  {
						  $str=substr($str,2,$l);
						  $l=strlen($str);
						  $text=$str;
						  find();
						  }
						  else
						  {
						  $mess=explode(&quote; &quote;,$str);
						  $n=sizeof($mess);
							//echo $n.&quote;--&quote;;
						  for($i=0;$i<$n;$i++)
						  {
						  $text=$mess&#1111;$i];
						  $l=strlen($text);
						  if($l!=0)
						  find();
						  }
						  }
						  function find()
						  {
						  global $text;
						  //$text=strtolower($text);
						  //echo $text.&quote;<br>&quote;;
						  $i=0;
						  $j=2;
						  $dirname=&quote;.&quote;;
						  $dh=opendir($dirname);
						  $file=readdir($dh);
						  while ($file !=false)
						  {
						  $path = $dirname.&quote;/&quote;.$file;
						  if(is_dir($path))
						  {
						  $names&#1111;$i]=$path;
						  $i=$i+1;
						  }
						  if(is_file($path))
						  {
						  $fp=fopen($path,&quote;r&quote;);
						  while(!feof($fp))
						  {
						  $line=fgets($fp,1024);
						  if(strstr($line,$text))
						  echo &quote;<a href=&quote;.$file.&quote;>  *  $file </a><br>&quote;;
						  }
						  }
						  $file=readdir($dh);
						  }
						  closedir($dh);
						  }s
						  ?>                        
						                  </p>
						    </div>
						  </form>
how do i get the results to show the target's page <title>???
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Well, once you've found the file, just parse it for <title> and </title>, and output it's contents

I would suggest that you either a) put the contents in a database or b) cache search data. Searching whole directories of files each time a search is done might start to be taxing on the server.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply