选择显示字体大小

php文本站内全文检索


<?php
/****************************************************  
原作者: uchinaboy
修改:lingshidao
特点:无需mysql支持;速度快;无需设置路径,放在哪级目录下,就搜索该目录和子目录;可以搜索一切文本类型的文件;显示文件相关内容;关键词自动高亮显示。
修改内容:增加了自动分页和风格设置文件。
搜索框代码(如果放在search.php相同目录下,无需修改):<form method=&quot;post&quot; action=&quot;search.php&quot;><input type=&quot;text&quot; name=&quot;key&quot; size=40 value=&quot;&quot;>  
<input type=&quot;submit&quot; value=&quot;检索&quot;></form>
****************************************************/
require (&quot;template.php&quot;);
echo &quot;<p align=\&quot;center\&quot;>&quot;;
echo &quot;检索结果&quot;;
echo &quot;</p><hr>&quot;;
if (function_exists(&quot;set_time_limit&quot;) && !get_cfg_var('safe_mode')){
set_time_limit(600);}
function get_msg(&#36;path) {
global &#36;key, &#36;i;
&#36;handle = opendir(&#36;path);
while (&#36;filename = readdir(&#36;handle)) {
//echo &#36;path.&quot;/&quot;.&#36;filename.&quot;<br>&quot;;
&#36;newpath = &#36;path.&quot;/&quot;.&#36;filename;
if (is_file(&#36;newpath)) {
&#36;fp = fopen(&#36;newpath, &quot;r&quot;);
&#36;msg = fread(&#36;fp, filesize(&#36;newpath));
fclose(&#36;fp);
match_show(&#36;key, &#36;msg, &#36;newpath, &#36;filename);
}
if (is_dir(&#36;path.&quot;/&quot;.&#36;filename) && (&#36;filename != &quot;.&quot;) && (&#36;filename != &quot;..&quot;)) {
//echo &quot;<br><br><br>&quot;.&#36;newpath.&quot;<br><br><br>&quot;;
get_msg(&#36;path.&quot;/&quot;.&#36;filename);
}
}
closedir(&#36;handle);
return &#36;i;
}

function match_show(&#36;key, &#36;msg, &#36;newpath, &#36;filename) {
global &#36;i;
&#36;key = chop(&#36;key);
if(&#36;key) { &#36;check_type = preg_match(&quot;/\.html?&#36;/&quot;, &#36;filename);
if(&#36;check_type) {&#36;title = gethtmltitle(&#36;msg);}
&#36;msg = preg_replace(&quot;/<style>.+<\/style>/is&quot;, &quot;&quot;, &#36;msg);
&#36;msg = preg_replace(&quot;/<[^>]+>/&quot;, &quot;&quot;, &#36;msg);
&#36;value = preg_match(&quot;/.*&#36;key.*/i&quot;, &#36;msg, &#36;res);
if(&#36;value) {
 

if(&#36;title) {&#36;m = &#36;title;} else {&#36;m = &#36;filename;}
&#36;i++;
上一篇      目录      下一篇 = &#36;newpath;
echo &quot;&#36;i.◆<a href=\&quot;上一篇      目录      下一篇\&quot;>&#36;m</a><br><br>&quot;;
}
}else {
echo &quot;请输入关键词&quot;;
exit;
}
}

function gethtmltitle(&#36;msg) {

/* locate where <title> is located in html file. */
&#36;lbound = strpos(&#36;msg, '<title>') + 7; //7 is the lengh of <title>.

if (&#36;lbound < 1)
return;

/* locate where </title> is located in html file. */
&#36;ubound = strpos(&#36;msg, '</title>', &#36;lbound);

if (&#36;ubound < &#36;lbound)
return;

/* clean html and php tags out of &#36;title with the madness below. */
&#36;title = ereg_replace(&quot;[\t\n\r]&quot;, '', substr(&#36;msg, &#36;lbound, &#36;ubound - &#36;lbound));
&#36;title = trim(strip_tags(&#36;title));

if (strlen(&#36;title) < 1) //a blank title is worthless.
return;

return &#36;title;
}

&#36;i = get_msg(&quot;.&quot;);
echo &quot;<hr><p align=\&quot;center\&quot;>&quot;;
echo &quot; 已经搜索到了 &#36;i 条信息&quot;;
?>

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons