Home >php教程 >php手册 >站内搜索HTML版

站内搜索HTML版

WBOY
WBOYOriginal
2016-06-13 10:41:231111browse

 

<ol class="dp-c">
<li class="alt"><span><span><?php     </span></span></span></li>
<li>
<span class="comment">/****************************************************    </span> </li>
<li class="alt"><span><span class="comment">program : Spr2[search_html]    </span> </span></li>
<li><span><span class="comment">Author  : uchinaboy     </span> </span></li>
<li class="alt"><span><span class="comment">E-mail  : uchinaboy@163.com    </span> </span></li>
<li><span><span class="comment">QQ      : 16863798    </span> </span></li>
<li class="alt"><span><span class="comment">Date    : 2001-8-9   </span> </span></li>
<li><span><span class="comment">****************************************************/</span><span>    </span></span></li>
<li class="alt">
<span class="comment">//require("config.inc.php");   </span><span> </span>
</li>
<li><span> </span></li>
<li class="alt">
<span class="keyword">function</span><span> get_msg(</span><span class="vars">$path</span><span>) {    </span>
</li>
<li>
<span class="keyword">global</span><span> </span><span class="vars">$key</span><span>, </span><span class="vars">$i</span><span>;    </span>
</li>
<li class="alt">
<span class="vars">$handle</span><span> = opendir(</span><span class="vars">$path</span><span>);    </span>
</li>
<li>
<span class="keyword">while</span><span> (</span><span class="vars">$filename</span><span> = readdir(</span><span class="vars">$handle</span><span>)) {    </span>
</li>
<li class="alt">
<span class="comment">//echo $path."/".$filename."<br>";   </span><span> </span>
</li>
<li>
<span class="vars">$newpath</span><span> = </span><span class="vars">$path</span><span>.</span><span class="string">"/"</span><span>.</span><span class="vars">$filename</span><span>;    </span>
</li>
<li class="alt">
<span class="vars">$check_type</span><span> = preg_match(</span><span class="string">"/.html?$/"</span><span>, </span><span class="vars">$filename</span><span>);    </span>
</li>
<li>
<span class="keyword">if</span><span> (</span><span class="func">is_file</span><span>(</span><span class="vars">$newpath</span><span>) && </span><span class="vars">$check_type</span><span>) {    </span>
</li>
<li class="alt">
<span class="vars">$fp</span><span> = </span><span class="func">fopen</span><span>(</span><span class="vars">$newpath</span><span>, </span><span class="string">"r"</span><span>);    </span>
</li>
<li>
<span class="vars">$msg</span><span> = </span><span class="func">fread</span><span>(</span><span class="vars">$fp</span><span>, </span><span class="func">filesize</span><span>(</span><span class="vars">$newpath</span><span>));    </span>
</li>
<li class="alt">
<span>fclose(</span><span class="vars">$fp</span><span>);    </span>
</li>
<li>
<span>match_show(</span><span class="vars">$key</span><span>, </span><span class="vars">$msg</span><span>, </span><span class="vars">$newpath</span><span>, </span><span class="vars">$filename</span><span>);    </span>
</li>
<li class="alt"><span>}    </span></li>
<li>
<span class="keyword">if</span><span> (</span><span class="func">is_dir</span><span>(</span><span class="vars">$path</span><span>.</span><span class="string">"/"</span><span>.</span><span class="vars">$filename</span><span>) && (</span><span class="vars">$filename</span><span> != </span><span class="string">"."</span><span>) &&  (</span><span class="vars">$filename</span><span> != </span><span class="string">".."</span><span>)) {    </span>
</li>
<li class="alt">
<span class="comment">//echo "<br><br><br>".$newpath."<br><br><br>";   </span><span> </span>
</li>
<li>
<span>get_msg(</span><span class="vars">$path</span><span>.</span><span class="string">"/"</span><span>.</span><span class="vars">$filename</span><span>);    </span>
</li>
<li class="alt"><span>}    </span></li>
<li><span>}    </span></li>
<li class="alt">
<span class="func">closedir</span><span>(</span><span class="vars">$handle</span><span>);    </span>
</li>
<li>
<span class="keyword">return</span><span> </span><span class="vars">$i</span><span>;    </span>
</li>
<li class="alt"><span>}    </span></li>
<li><span> </span></li>
<li class="alt">
<span class="keyword">function</span><span> match_show(</span><span class="vars">$key</span><span>, </span><span class="vars">$msg</span><span>, </span><span class="vars">$newpath</span><span>, </span><span class="vars">$filename</span><span>) {    </span>
</li>
<li>
<span class="keyword">global</span><span> </span><span class="vars">$key</span><span>, </span><span class="vars">$i</span><span>;    </span>
</li>
<li class="alt">
<span class="vars">$key</span><span> = </span><span class="func">chop</span><span>(</span><span class="vars">$key</span><span>);    </span>
</li>
<li>
<span class="keyword">if</span><span> (</span><span class="vars">$key</span><span>) {    </span>
</li>
<li class="alt">
<span class="vars">$msg</span><span> = preg_replace(</span><span class="string">"/<style>.+</style>/is"</span><span>, </span><span class="string">""</span><span>, </span><span class="vars">$msg</span><span>);    </span>
</li>
<li>
<span class="vars">$msg</span><span> = </span><span class="func">str_replace</span><span>(</span><span class="string">" "</span><span>, </span><span class="string">""</span><span>, </span><span class="vars">$msg</span><span>);    </span>
</li>
<li class="alt">
<span class="vars">$msg</span><span> = preg_replace(</span><span class="string">"/]+>/"</span><span>, </span><span class="string">""</span><span>, </span><span class="vars">$msg</span><span>);    </span>
</li>
<li>
<span class="vars">$value</span><span> = preg_match(</span><span class="string">"/.*$key.*/i"</span><span>, </span><span class="vars">$msg</span><span>, </span><span class="vars">$res</span><span>);    </span>
</li>
<li class="alt">
<span class="keyword">if</span><span> (</span><span class="vars">$value</span><span>) {    </span>
</li>
<li>
<span class="vars">$res</span><span>[0] = preg_replace(</span><span class="string">"/$key/i"</span><span>, </span><span class="string">"<font>$key</font>"</span><span>, </span><span class="vars">$res</span><span>[0]);    </span>
</li>
<li class="alt">
<span class="vars">$i</span><span>++;    </span>
</li>
<li>
<span class="vars">$link</span><span> = </span><span class="vars">$newpath</span><span>;    </span>
</li>
<li class="alt">
<span>print </span><span class="string">"<a>$filename</a><br>"</span><span>;    </span>
</li>
<li>
<span>print </span><span class="vars">$res</span><span>[0].</span><span>
</span>
</li>
</ol>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn