这篇文章主要介绍了以文本文件为基础的PHP搜索引擎,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
相关推荐:
php 读取文本文件并逐行输出该行使用最多的字符与对应次数的方法实例详解
<html> <head> <title> 搜索关键字是——<? "$keyyword" ?> </title> </head> <body bgcolor=yellow text=green> <form method=post action=search.php> <input type=text name=keyword> <br> <br> <input type=submit value=搜索> </form> <hr> <h2><b><u>Search results...</u></b></h2> <hr> <? if(!$keyword) { echo "请输入关键字!<br>"; exit; } $fl="keywords.txt"; //保存搜索数据的文本文件 $fp=fopen($fl, "r"); if(!fp) { echo "无法读取数据文件!!"; } $fr=fread($fp, filesize($fl)); $line=explode("/n", $fr); $id=0; for($i=0; $i<count($line); $i++) { $lin=explode("|", $line[$i]); if(eregi("$keyword", "$lin[0]")) { echo "<a href=$lin[1]>$lin[1]</a><br><spacer type=horizontal size=40>$lin[2]<br><br>"; } else { $id++; } } if($id==count($line)) { echo "找不到匹配的结果!"; } ?> </body> </html>
以上就是以文本文件为基础的PHP搜索引擎的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号