Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 14th, 2005, 2:01 AM   #1
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 403
Rep Power: 3 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
PHP search engine script

The search engine on my website (Jolly Roger's Ship ) is created using PHP. I wanted to put a search engine on my website, but I couldn't find a single tutorial out there, so instead I'm posting my source code and hope it helps people out. It uses two files 'results.php' and 'search.php' along with text files which contain all the sites the search engine can look for.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Sep 14th, 2005, 2:02 AM   #2
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 403
Rep Power: 3 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Filename: search.php
Purpose: The user interface for the search engine.

<html>
	<head>
		<title>
			JRSearch
		</title>
	</head>
	<body bgcolor="#000031" link="##91DAFF" vlink="##91DAFF">
		<table height="100%" width="100%" border="0" cellpadding="0">
			<td width="115" align="left" valign="top" rowspan="2">
				<font color="##91DAFF" face="verdana" size="1">
					JRSearch<br>
					<br>
				</font>
				<img src="../skull.gif">
			</td>
			<td width="1" bgcolor="#FFFFFF"align="left" valign="top" rowspan="2">
			</td>
			<td background="../jr.gif" align="left" valign="top">
				<font color="#F8BF24" face="verdana" size="1">
					Please select a database and type in your query.
				</font>
				<form method="get" action="search.php">
					<table cellpadding="0" cellspacing="0" width="100%">
						<td valign="top">
							<font color="#FFFFFF" face="verdana" size="1">
								Database:<br>
								<select name="database" size="4">
									<option>1. Anime</option>
									<option>2. Graphics</option>
									<option>3. Miscellaneous</option>
									<option>4. Music</option>
									<option>5. Reference</option>
									<option>6. Video Games</option>
									<option>7. World Wide Web</option>
								</select><br><br>
								<input type="text" name="sendstring" size="19" maxlength="40">&nbsp;
								<input type="submit" value="Search">&nbsp;	
								<input type="reset" value="Clear">
							</font>
						</td>
						<td align="right" valign="bottom">
							<font color="#FFFFFF" face="verdana" size="1">
								<font color="#F8BF24">
									*IMPORTANT*<br>
								</font>
								<br>
								<a href="tips.html" target="_self"><b>Tips for using JRSearch.</b></a><br>
								<br>
								<a href="submit.html" target="_blank">Submit a site.</a><br>
								<br>
								<a href="about.html" target="_self">About JRSearch.</a><br>
								<br>
								<a href="../contact/contact.html" target="_main">Dead or broken link?</a>
							</font>
						</td>
					</table>
				</form>
<?php
	switch(count($_GET))
	{
		case 0:
			echo '<iframe src="results.php" width="100%"  height="*"></iframe>';
			break;
		default:
			echo '<iframe src="results.php?sendstring=' . stripslashes($_GET['sendstring']) . '&database=' . stripslashes($_GET['database']) . '" width="100%" height="*"></iframe>';
			break;
	}
?>
				<font color="#F8BF24" face="verdana" size="1">
					<br><br>
					Jolly Roger's Ship accepts no responsibility for the content on any website featured herein.  The content provided by these websites is the sole product of its respective web personnel.  You are free to search at own risk if you understand this, otherwise we suggest you exit this site.
				</font>
			</td>
		</table>
	</body>
</html>
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Sep 14th, 2005, 2:03 AM   #3
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 403
Rep Power: 3 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Filename: results.php
Purpose: To find sites based on user input and output them in a structured manner.

<html>
	<head>
		<title>
			Search Results
		</title>
	</head>
	<body background="../jr.gif" bgcolor="#000031" link="##91DAFF" vlink="##91DAFF">
		<font color="#FFFFFF" face="verdana" size="1">
<?php
	switch(count($_GET))
	{
		case 0:
			echo 'Welcome to JRSearch.';
			break;
		default:
			$searchstring = strtolower($_GET['sendstring']);
			$searchbase = $_GET['database'];
			if($searchstring == NULL)
			{
				die('You did not enter a search term.');
			}
			if($searchbase == NULL)
			{
				die('You did not select a database.');
			}

			$searchbase = substr($searchbase, 0, strpos($searchbase, "."));

			$i = 1;
			
			switch($searchbase)
			{
				case $i++:
					$filename = 'anime';
					$searchbase = 'anime';
					break;
				case $i++:
					$filename = 'graphics';
					$searchbase = 'graphics';
					break;
				case $i++:
					$filename = 'misc';
					$searchbase = 'miscellaneous';
					break;
				case $i++:
					$filename = 'music';
					$searchbase = 'music';
					break;
				case $i++:
					$filename = 'reference';
					$searchbase = 'reference';
					break;
				case $i++:
					$filename = 'vgames';
					$searchbase = 'video games';
					break;
				case $i++:
					$filename = 'web';
					$searchbase = 'world wide web';
					break;
			}

			$filename .= '.txt';
			if(!$handle = fopen($filename, 'r'))
			{
				echo "Cannot open file ($filename)";
				exit();
			}
			$contents = fread($handle, filesize($filename));
			fclose($handle);
	
			$end_tag = 'EOINPUT';
			$thread_contents = explode($end_tag, $contents);
			unset($thread_contents[count($thread_contents) - 1]);

			echo '<font color="#F8BF24"><strong>';
			echo intval(count($thread_contents) / 4);
			echo '</strong></font> total sites in <font color="#F8BF24"><strong>';
			echo strtoupper($searchbase);
			echo'</strong></font> database<br><br>';

			$n = 0;

			for($i = 0; $i < count($thread_contents); $i += 4)
			{
				$title = $thread_contents[$i + 0];
				$desc = $thread_contents[$i + 1];
				$url = $thread_contents[$i + 2];
				$kword = strtolower($thread_contents[$i + 3]);
				$kword .= 'list_all';

				if(is_int(strpos($kword, $searchstring)))
				{
					$n ++;
					echo '<font color="#F8BF24"><strong>';
					echo $n;
					echo '</strong></font>. <a href="';
					echo $url;
					echo '" target="_blank">';
					echo $title;
					echo '</a><br>';
					echo $desc;
					echo '<hr>';
				}
			}
			if($n == 0)
			{
				echo 'No results found.';
			}
			break;
	}
?>
		</font>
	</body>
</html>
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Sep 14th, 2005, 2:11 AM   #4
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 403
Rep Power: 3 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
The text files that the search engine looks through are structured in the following manner:

TitleEOINPUTDescriptionEOINPUTurlEOINPUTkeywordsEOINPUT

The EOINPUT are the tags used to separate the content based on heredoc syntax. So in the previous structure you'd only have one website. For instance, my website's particular descriptor would look like this:

Jolly Roger's Ship :: Ver. 1.3EOINPUTJolly Roger's Ship, the only website on the net powered by atomic kittens.EOINPUThttp://grimpirate.t35.com/EOINPUTgrimpirate, grim pirate, jr, jolly roger's ship, ray dream, search engine, jrsearch, haohmaru faq, haohmaru strategy guide, samurai showdown trading cards, vagrant skull, online comic, guilty gear gif, guilty gear x gif, anime reviews, anime intros, anime openings, super robot wars alpha buddy icons, dungeons and dragons, dnd accurate combat engine, nyko air flo pc controller, mugen, cd cases, cd slips, ansi c program, source code, php5, jrforum, forum, webboardEOINPUT

The title, description, and keywords are taken directly from the particular site from the meta tags available in the headers of most main pages of a site. If there's more than one website in a particular database, the descriptors are appended to one another.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Sep 14th, 2005, 11:05 PM   #5
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
Hmm. Interesting stuff, thanks for sharing.
__________________
--John Cruz
Web Developer
www.cruzweb.net
Lich is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:52 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC