Current location: Hot Scripts Forums » Programming Languages » PHP » search engine question


search engine question

Reply
  #1 (permalink)  
Old 08-04-03, 10:17 PM
herman herman is offline
New Member
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question search engine question

i've found php coding -- searching within html site (w/o using MySQL) in website.

I can use it, but the problem is the search result shows out a continous wordings w/o any spacing.

eg. i search "good"
the search result will show like this:

==> HotScripts.comisagoodsite.


But not like other search engine shows like this:

==> HotScripts.com is a good site.


the php script as follow:
PHP Code:

<?php  

/****************************************************   
<form method="post" action="search.php">
<input type="text" name="key" size=40 value="">                         
<input type="submit" value="Search"></form>
****************************************************/  
require ("template.php");

function 
get_msg($path) {  
global 
$key$i;  
$handle opendir($path);  
while (
$filename readdir($handle)) {  
//echo $path."/".$filename."<br>";  
$newpath $path."/".$filename;  
if (
is_file($newpath)) {  
$fp fopen($newpath"r");  
$msg fread($fpfilesize($newpath));  
fclose($fp);  
match_show($key$msg$newpath$filename);  
}  
if (
is_dir($path."/".$filename) && ($filename != ".") &&  ($filename != "..")) {  
//echo "<BR><BR><BR>".$newpath."<BR><BR><BR>";  
get_msg($path."/".$filename);  
}  
}  
closedir($handle);  
return 
$i;  
}  

function 
match_show($key$msg$newpath$filename) { 
  global 
$ar$i
  
$key chop($key); 
  if(
$key) { 
    
$msg preg_replace("/<style>.+<\/style>/is"""$msg); 
    
$msg str_replace(" """$msg); 
    
$msg preg_replace("/<[^>]+>/"""$msg); 
    
$value preg_match("/.*$key.*/i"$msg$res); 
    if(
$value) { 
      
$res[0] = preg_replace("/$key/i""<FONT COLOR=\"orange\">$key</FONT>"$res[0]); 
      
$i++; 
      
$link $newpath
      
$ar[] = "<img src=\"../images/bullet_news.gif\" width=\"16\" height=\"16\">&nbsp;<a href=\"$link\" class=\"contentArial\">$filename</a><BR><BR>" $res[0]."<BR><br>"
      
//$ar[] = "$i.<img src=\"../images/bullet_news.gif\" width=\"16\" height=\"16\">&nbsp;<a href=\"$link\" class=\"contentArial\">$filename</a><BR><BR>" . $res[0]."<BR><br>"; 
    

  }else { 
    echo 
"Please enter keywords to search"
    exit; 
  } 

$i get_msg(".");
if (empty(
$page)) $page=1;
$maxresult=($page*20);
$resultcount count($ar);
if (
$resultcount%20==0$maxpageno=$resultcount/20;
    else 
$maxpageno=floor($resultcount/20)+1;
if (
$page>$maxpageno) { $page=$maxpageno$pagemax=$resultcount-1$pagemin=max(0,$result_count-20);}
    elseif (
$page==1) {$pagemin=0$pagemax=min($result_count-1,20-1); }
    else { 
$pagemin=min($resultcount-1,20*($page-1)); $pagemax=min($resultcount-1,$pagemin+20-1); }
$maxresult=min($maxresult,$resultcount);
echo 
"<p class=\"contentArial\">";
echo 
"Search result:";
echo 
"</p><img src=\"../images/hoz_bar.jpg\" width=\"310\" height=\"2\"><br><br>";
for (
$i=max(0,$maxresult-20); $i<$maxresult$i++) {
print 
$ar[$i];
}
echo 
"<img src=\"../images/hoz_bar.jpg\" width=\"310\" height=\"2\"><p class=\"contentArial\">";
echo 
" seaching $resultcount pages";
      
$nextpage=$page+1;
      
$previouspage=$page-1;
echo 
" --- | <a href='result.php?key=$key&page=$previouspage' class=\"contentArial\" target='_self'>previous 20 results</a> |";
echo 
" | <a href='result.php?key=$key&page=$nextpage' class=\"contentArial\" target='_self'>next 20 results</a> |";
echo 
"</p>";
exit;

?>
Reply With Quote
  #2 (permalink)  
Old 08-04-03, 10:56 PM
inkblot's Avatar
inkblot inkblot is offline
The Lonely Coder
 
Join Date: Aug 2003
Location: Ontario
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Looking at it quickly, it would seem that this line:
PHP Code:

$msg str_replace(" """$msg); 

is stripping the spaces from the search result before you match the keyword. I can't see why that would be necessary... maybe I'm wrong.
__________________
where am i......
Reply With Quote
  #3 (permalink)  
Old 08-04-03, 11:41 PM
herman herman is offline
New Member
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Quote:
Originally posted by inkblot
Looking at it quickly, it would seem that this line:
PHP Code:

$msg str_replace(" """$msg); 

is stripping the spaces from the search result before you match the keyword. I can't see why that would be necessary... maybe I'm wrong.

thx!!! inkblot

after i comment this line, it restores to what i want. Thanks!!!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SEO Expert Available nakulgoyal Job Offers & Assistance 2 08-14-04 12:38 PM
PHP search engine flipsix PHP 3 10-19-03 02:07 PM
Redirects v.s. Search Engine Indexing RPGBarb Script Requests 1 09-12-03 11:34 PM
search engine help darkcarnival PHP 5 08-08-03 07:27 AM
How to do a search engine?? bonnie ASP 7 07-07-03 03:41 AM


All times are GMT -5. The time now is 04:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.