use*_*812 7 html php forms directory search
基本上我有一个旧的静态HTML网站(http://www.brownwatson.co.uk/brochure/page1.html)我需要添加一个搜索框来搜索一个名为/ brochure的文件夹中的文件夹是html文档和图像等我需要搜索以查找ISBN号,书籍参考号,标题等.没有数据库托管服务提供商有PHP我试图创建这样的东西:
<div id="contentsearch">
<form id="searchForm" name="searchForm" method="post" action="search.php">
<input name="search" type="text" value="search" maxlength="200" />
<input name="submit" type="submit" value="Search" />
</form>
<?php
$dir = "/brochure/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($file == $_POST['search']){
echo('<a href="'.$dir . $file.'">'. $file .'</a>'."\n");
}
}
closedir($dh);
}
}
?>
</div>
Run Code Online (Sandbox Code Playgroud)
我知道,我知道这很糟糕,不会有任何想法吗?多年来我没有创建这样的东西,而且几乎只需要一些代码并将它们粘在一起!
Len*_*ood 13
有很多解决方案可供选择.没有特别的顺序:
免费或开源
另见http://indieweb.org/search#Software
订阅(又名付费)服务:
pix*_*pix 10
一个非常非常懒的选项(为避免设置Google自定义搜索引擎)是制作一个指向Google的表单,其中隐藏的查询元素将搜索限制在您自己的网站上:
<div id="contentsearch">
<form id="searchForm" name="searchForm" action="http://google.com/search">
<input name="q" type="text" value="search" maxlength="200" />
<input name="q" type="hidden" value="site:mysite.com"/>
<input name="submit" type="submit" value="Search" />
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
除了懒惰之外,与CSE相比,此方法可以让您更好地控制搜索表单的外观.
如果您的网站已被 Google 很好地索引,那么一个快速且现成的解决方案是使用Google CSE。
除了具有硬编码 html 页面和包含图像的目录的静态网站之外;是的,可以创建搜索机制。但相信我,这比创建动态网站更加忙碌和消耗资源。
使用 PHP 在目录和文件中搜索效率非常低。我建议不要提供复杂的 PHP 解决方法,而是选择动态 CMS 驱动的网站。
| 归档时间: |
|
| 查看次数: |
13712 次 |
| 最近记录: |