Read an old article: PHP text station full Text Search

Source: Internet
Author: User
Tags key
Full-Text Search <?php
/****************************************************
Original Author: Uchinaboy
Modification: Lingshidao
Features: No MySQL support, fast, no need to set the path, in which level of directory to search the directory and subdirectories, you can search for all text types of files, display file-related content, keywords automatically highlighted.
Modified content: Added automatic paging and styling files.
Search box code (if placed in the same directory search.php, do not need to modify): <form method= "POST" action= "search.php" ><input type= "text" name= "key" size =40 value= "" >
<input type= "Submit" value= "Search" ></form>
****************************************************/
Require ("template.php");
echo "<p align=\" Center\ ">";
echo "Search results";
echo "</p>if (function_exists ("Set_time_limit") &&!get_cfg_var (' Safe_mode ')) {
Set_time_limit (600);}
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 ($fp, FileSize ($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 $i;
$key = Chop ($key);
if ($key) {$check _type = Preg_match ("/\.html?$/", $filename);
if ($check _type) {$title = Gethtmltitle ($msg);}
$msg = Preg_replace ("/<style>.+<\/style>/is", "", $msg);
$msg = Preg_replace ("/<[^>]+>/", "", $msg);
$value = Preg_match ("/.* $key. */i", $msg, $res);
if ($value) {


if ($title) {$m = $title;} else {$m = $filename;}
$i + +;
$link = $newpath;
echo "$i. <a href=\" $link > $m </a><BR><BR> ";
}
}else {
echo "Please input keywords";
Exit
}
}

function Gethtmltitle ($msg) {

/* Locate where <title> is located in HTML file. */
$lBound = Strpos ($msg, ' <title> ') + 7; 7 is the lengh of <title>.

if ($lBound < 1)
Return

/* Locate where </TITLE> is located in HTML file. */
$uBound = Strpos ($msg, ' </title> ', $lBound);

if ($uBound < $lBound)
Return

/* Clean HTML and PHP tags out of $title with the madness below. */
$title = Ereg_replace ("[\t\n\r]", "", substr ($msg, $lBound, $uBound-$lBound));
$title = Trim (Strip_tags ($title));

if (strlen ($title) < 1)//a blank title is worthless.
Return

return $title;
}

$i = Get_msg (".");
echo "echo "has searched for $i message";
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.