Skip to content

Instantly share code, notes, and snippets.

@zquestz
Created May 11, 2010 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zquestz/396918 to your computer and use it in GitHub Desktop.
Save zquestz/396918 to your computer and use it in GitHub Desktop.
<?php
function check_terms($line, $search_terms) {
$retval = true;
$matrix = array();
foreach ($search_terms as $term) {
if (strpos(strtolower($line), strtolower($term)) > 0) {
array_push($matrix, true);
} else {
array_push($matrix, false);
}
}
if (in_array(false, $matrix)) {
$retval = false;
}
return $retval;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Infinity</title>
<link rel="stylesheet" href="css/main.css" type="text/css" media="screen" title="main" charset="utf-8">
</head>
<body>
<div id="symbol">
<img src="images/infinity_badymaru.png" alt="∞" title="∞">
</div>
<div id="links">
<div class="link">[ <a href="https://192.168.1.17">Admin</a> ]</div><div class="link">[ <a href="https://192.168.1.7">The Lag</a> ]</div>
</div>
<div id="search">
<form action="index.php" method="get">
Search: <input type="text" name="search" />
</form>
</div>
<div id="results">
<?php
# Make sure they searched for something
if ($_GET['search'] != "") {
# Get 'search' param
$search_term = $_GET['search'];
# Get array of Search Terms
$search_terms = explode(" ", $search_term);
# Path you want trimed from the left of the input file
$path_trim = '/share/Infinity/Bases/Default/';
# Find what they searched for in file_list.txt
$lines = file('file_list.txt');
# Max number of hits
$max = 250;
# Initialize output array and counter
$output = array();
$x = 0;
# Loop through lines of file
foreach ($lines as $line) {
if (check_terms($line, $search_terms)) {
array_push($output, $line);
$x++;
if ($x == $max) {
break;
}
}
$lines = $output;
}
echo "<h3>Search Results - '" . htmlspecialchars($search_term) . "' (" . $x . ")</h3>\n";
foreach ($lines as $li) {
if ($li != "") {
$filename = explode("/", $li);
echo "<div class='search_result'><b><span class='bell'>Ω</span> " . htmlspecialchars($filename[count($filename) - 1]) . "</b><br />\n - " . ltrim(htmlspecialchars($li), $path_trim) . "</div>\n";
}
}
if ($max == $x) {
echo "<p><b>Internal limit hit (" . $max . ") for one of your search terms. Please refine your search.</b></p>";
} elseif ($x == 0) {
echo "<p><b>No results.</b></p>";
}
}
?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment