www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP Newbie Question (Search Output Results)

  1. #1
    Join Date
    Jul 2007
    Posts
    461

    PHP Newbie Question (Search Output Results)

    Hi I found this Search MySite script and I was wondering if someone could tell me how I might be able to output it's results onto a new page. Thanks so much.

    Code:
    <?
    
    // English Configuration
    $my_server = "http://".getenv("SERVER_NAME").":".getenv("SERVER_PORT"); // Your Server (generally no changes needed)
    $my_root = getenv("DOCUMENT_ROOT"); // Your document root (generally no changes needed)
    $s_dirs = array("/cars/car-3","/cars/car-3/search/dir1"); // Which directories should be searched ("/dir1","/dir2","/dir1/subdir2","/Verzeichniss2/Unterverzeichniss2")? --> $s_dirs = array(""); searches the entire server
    $s_skip = array("..",".","subdir2"); // Which files/dirs do you like to skip?
    $s_files = "html|htm|HTM|HTML|php3|php4|php|txt"; // Which files types should be searched? Example: "html$|htm$|php4$"
    $min_chars = "3"; // Min. chars that must be entered to perform the search
    $max_chars = "30"; // Max. chars that can be submited to perform the search
    $default_val = "Searchphrase"; // Default value in searchfield
    $limit_hits = array("5","10","25","50","100"); // How many hits should be displayed, to suppress the select-menu simply use one value in the array --> array("100")
    $message_1 = "Invalid Searchterm!"; // Invalid searchterm
    $message_2 = "Please enter at least '$min_chars', highest '$max_chars' characters."; // Invalid searchterm long ($min_chars/$max_chars)
    $message_3= "Your searchresult for:"; // Headline searchresults
    $message_4 = "Sorry, no hits."; // No hits
    $message_5 = "results"; // Hits
    $message_6 = "Match case"; // Match case
    $no_title = "Untiteled"; // This should be displayed if no title or empty title is found in file
    $limit_extracts_extracts = ""; // How many extratcts per file do you like to display. Default: "" --> every extract, alternative: 'integer' e.g. "3"
    $byte_size = "51200"; // How many bytes per file should be searched? Reduce to increase speed
    
    
    //ini_set("error_reporting", "2047"); // Debugger
    
    // search_form(): Gibt das Suchformular aus
    function search_form($HTTP_GET_VARS, $limit_hits, $default_val, $message_5, $message_6, $PHP_SELF) {
    	@$keyword=$HTTP_GET_VARS['keyword'];
    	@$case=$HTTP_GET_VARS['case'];
    	@$limit=$HTTP_GET_VARS['limit'];
    	echo
    	"<form action=\"$PHP_SELF\" method=\"GET\">\n",
    	"<input type=\"hidden\" value=\"SEARCH\" name=\"action\">\n",
    	"<input type=\"text\" name=\"keyword\" class=\"text\" size=\"10\"  maxlength=\"30\" value=\"";
    	if(!$keyword)
    		echo "$default_val";
    	else
    		echo str_replace("&amp;","&",htmlentities($keyword));
    	echo "\" ";
    	echo "onFocus=\" if (value == '";
    	if(!$keyword)
    		echo "$default_val"; 
    	else
    		echo str_replace("&amp;","&",htmlentities($keyword));
    	echo "') {value=''}\" onBlur=\"if (value == '') {value='";
    	if(!$keyword)
    		echo "$default_val"; 
    	else
    		echo str_replace("&amp;","&",htmlentities($keyword));
    	echo "'}\"> ";
    	$j=count($limit_hits);
    	if($j==1)
    		echo "<input type=\"hidden\" value=\"".$limit_hits[0]."\" name=\"limit\">";
    	elseif($j>1) {
    		echo
    		"<select name=\"limit\" class=\"select\">\n";
    		for($i=0;$i<$j;$i++) {
    			echo "<option value=\"".$limit_hits[$i]."\"";
    			if($limit==$limit_hits[$i])
    				echo "SELECTED";
    			echo ">".$limit_hits[$i]." $message_5</option>\n";
    			}
    		echo "</select> ";
    		}
    	echo
    	"<input type=\"submit\" value=\"OK\" class=\"button\">\n",
    	"<br>\n",
    	"<span class=\"checkbox\">$message_6</span> <input type=\"checkbox\" name=\"case\" value=\"true\" class=\"checkbox\"";
    	if($case)
    		echo " CHECKED";
    	echo
    	">\n",
    	"<br>\n",
    	"<a href=\"http://www.terraserver.de/\" class=\"ts\" target=\"_blank\">Powered by terraserver.de/search</a>",
    	"</form>\n";
    	}
    
    
    // search_headline(): Ueberschrift Suchergebnisse
    function search_headline($HTTP_GET_VARS, $message_3) {
    	@$keyword=$HTTP_GET_VARS['keyword'];
    	@$action=$HTTP_GET_VARS['action'];
    	if($action == "SEARCH") // Volltextsuche
    		echo "<h1 class=\"result\">$message_3 '<i>".htmlentities(stripslashes($keyword))."</i>'</h1>";
    	}
    
    
    // search_error(): Auf Fehler testen und Suchfehler anzeigen
    function search_error($HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits) {
    	global $HTTP_GET_VARS;
    	@$keyword=$HTTP_GET_VARS['keyword'];
    	@$action=$HTTP_GET_VARS['action'];
    	@$limit=$HTTP_GET_VARS['limit'];
    	if($action == "SEARCH") { // Volltextsuche
    		if(strlen($keyword)<$min_chars||strlen($keyword)>$max_chars||!in_array ($limit, $limit_hits)) { // Ist die Anfrage in Ordnung (min. '$min_chars' Zeichen, max. '$max_chars' Zeichen)?
    			echo "<p class=\"result\"><b>$message_1</b><br>$message_2</p>";
    			$HTTP_GET_VARS['action'] = "ERROR"; // Suche abbrechen
    			}
    		}
    	}
    
    
    // search_dir(): Volltextsuche in Verzeichnissen
    function search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS) {
    	global $count_hits;
    	@$keyword=$HTTP_GET_VARS['keyword'];
    	@$action=$HTTP_GET_VARS['action'];
    	@$limit=$HTTP_GET_VARS['limit'];
    	@$case=$HTTP_GET_VARS['case'];
    	if($action == "SEARCH") { // Volltextsuche
    		foreach($s_dirs as $dir) { // Alle Verzeichnisse in $s_dirs durchsuchen
    			$handle = @opendir($my_root.$dir);
    			while($file = @readdir($handle)) {
    				if(in_array($file, $s_skip)) { // Alles in $skip auslassen
    					continue;
    					}
    				elseif($count_hits>=$limit) {
    					break; // Maximale Trefferzahl erreicht
    					}
    				elseif(is_dir($my_root.$dir."/".$file)) { // Unterverzeichnisse durchsuchen
    					$s_dirs = array("$dir/$file");
    					search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS); // search_dir() rekursiv auf alle Unterverzeichnisse aufrufen
    					}
    				elseif(preg_match("/($s_files)$/i", $file)) { // Alle Dateien gemaess Endungen $s_files
    					$fd=fopen($my_root.$dir."/".$file,"r");
    					$text=fread($fd, $byte_size); // 50 KB
    					$keyword_html = htmlentities($keyword);
    					if($case) { // Gross-/Kleinschreibung beruecksichtigen?
    						$do=strstr($text, $keyword)||strstr($text, $keyword_html);
    						}
    					else {
    						$do=stristr($text, $keyword)||stristr($text, $keyword_html);
    						}
    					if($do)	{
    						$count_hits++; // Treffer zaehlen
    						if(preg_match_all("=<title[^>]*>(.*)</title>=siU", $text, $titel)) { // Generierung des Link-Textets aus <title>...</title>
    							if(!$titel[1][0]) // <title></title> ist leer...
    								$link_title=$no_title; // ...also $no_title
    							else
    								$link_title=$titel[1][0];  // <title>...</title> vorhanden...
    							}
    						else {
    							$link_title=$no_title; // ...ansonsten $no_title
    							}
    						echo "<a href=\"$my_server$dir/$file\" target=\"_self\" class=\"result\">$count_hits.  $link_title</a><br>"; // Ausgabe des Links
    						$auszug = strip_tags($text);
    						$keyword = preg_quote($keyword); // unescapen
    						$keyword = str_replace("/","\/","$keyword");
    						$keyword_html = preg_quote($keyword_html); // unescapen
    						$keyword_html = str_replace("/","\/","$keyword_html");
    						echo "<span class=\"extract\">";
    						if(preg_match_all("/((\s\S*){0,3})($keyword|$keyword_html)((\s?\S*){0,3})/i", $auszug, $match, PREG_SET_ORDER)); {
    							if(!$limit_extracts)
    								$number=count($match);
    							else
    								$number=$limit_extracts;
    							for ($h=0;$h<$number;$h++) { // Kein Limit angegeben also alle Vorkommen ausgeben
    								if (!empty($match[$h][3]))
    									printf("<i><b>..</b> %s<b>%s</b>%s <b>..</b></i>", $match[$h][1], $match[$h][3], $match[$h][4]);
    								}
    							}
    						echo "</span><br><br>";
    						flush();
    						}
    					fclose($fd);
    					}
    				}
    	  		@closedir($handle);
    			}
    		}
    	}
    
    
    // search_no_hits(): Ausgabe 'keine Treffer' bei der Suche
    function search_no_hits($HTTP_GET_VARS, $count_hits, $message_4) {
    	@$action=$HTTP_GET_VARS['action'];
    	if($action == "SEARCH" && $count_hits<1) // Volltextsuche, kein Treffer
    		echo "<p class=\"result\">$message_4</p>";
    	}
    
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    </head>
    <body bgcolor="#FFFFFF" text="#000000" link="#03629C" vlink="#03629C" alink="#9D9D9D">
    <table border="0" cellspacing="1" cellpadding="0" bgcolor="#03629C">
      <tr align="left" valign="top">
    	<td>
    	  <table border="0" cellspacing="0" cellpadding="3" bgcolor="#FFFFFF">
    		<tr align="left" valign="top">
    		  <td>
    <?
    // search_form(): Gibt das Suchformular aus
    search_form($HTTP_GET_VARS, $limit_hits, $default_val, $message_5, $message_6, $PHP_SELF);
    ?>
    		  </td>
    		</tr>
    	  </table>	
    	</td>
      </tr>
    </table>
    <?
    // search_headline(): Ueberschrift Suchergebnisse
    search_headline($HTTP_GET_VARS, $message_3);
    // search_error(): Auf Fehler testen und Suchfehler anzeigen
    search_error($HTTP_GET_VARS, $min_chars, $max_chars, $message_1, $message_2, $limit_hits);
    // search_dir(): Volltextsuche in Verzeichnissen (siehe config.php4)
    search_dir($my_server, $my_root, $s_dirs, $s_files, $s_skip, $message_1, $message_2, $no_title, $limit_extracts, $byte_size, $HTTP_GET_VARS);
    // search_no_hits(): Ausgabe 'keine Treffer' bei der Suche
    search_no_hits($HTTP_GET_VARS, $count_hits, $message_4);
    ?>
    </body>
    </html>

  2. #2
    Join Date
    Jul 2007
    Posts
    461

    Resolved!

    Ridiculous carelessness on my part. Fixed, sorry - thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14700 seconds
  • Memory Usage 2,882KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (2)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates