只想搜索“我的朋友”;字符串";。使用指定的“";“字符串”;从搜索栏-PHP

只想搜索“我的朋友”;字符串";。使用指定的“";“字符串”;从搜索栏-PHP,php,html,string,file,search,Php,Html,String,File,Search,我对PHP很陌生。请帮忙:) 我只想让从搜索栏输入的字符串拉出一个文件名中包含该字符串的.html文件 基本上,我拥有的每个.html页面都显示了一个图书列表,其中每个.html页面都是按作者(即freud.html)划分的。所以,当我通过搜索栏搜索“弗洛伊德”书籍时,我想显示freud.html 我不知道如何将搜索栏字符串指向php文件。此外,我也不确定我搜索的字符串如何能够拉出我想要的.html文件,或者仅仅是一个错误页面 这是我的搜索栏: <div class="search-con

我对PHP很陌生。请帮忙:)

我只想让从搜索栏输入的字符串拉出一个文件名中包含该字符串的.html文件

基本上,我拥有的每个.html页面都显示了一个图书列表,其中每个.html页面都是按作者(即freud.html)划分的。所以,当我通过搜索栏搜索“弗洛伊德”书籍时,我想显示freud.html

我不知道如何将搜索栏字符串指向php文件。此外,我也不确定我搜索的字符串如何能够拉出我想要的.html文件,或者仅仅是一个错误页面

这是我的搜索栏:

<div class="search-container">
 <form action="searching.php">
   <input type="text" placeholder="Search Author..." name="search">
     <button type="submit"><i class="fa fa-search"></i></button>
 </form>
</div>

这是我在网上找到的PHP页面:

<?php
// string to search in a filename.
$searchString = 'myFile';

// all files in my/dir with the extension 
// .html 
$files = glob('/*.html');

// array populated with files found 
// containing the search string.
$filesFound = array();

// iterate through the files and determine 
// if the filename contains the search string.
foreach($files as $file) {
$name = pathinfo($file, PATHINFO_FILENAME);

// determines if the search string is in the filename.
if(strpos(strtolower($name), strtolower($searchString))) {
$filesFound[] = $file;
} 
}

// output the results.
print_r($filesFound);
?>

当表单:

 <form action="searching.php">
   <input type="text" placeholder="Search Author..." name="search">
     <button type="submit"><i class="fa fa-search"></i></button>
 </form>

如果是submit,GET请求将被发送到您的Web服务器,路径为
/search.php
,GET参数
search
=您的搜索输入。然后,Web服务器加载PHP文件
search.PHP
,并执行它

在PHP中,可以使用全局数组访问GET参数

因此,在PHP中,您可以使用
$\u GET[“search”]
访问搜索字符串


对于第二个问题,一旦找到HTML文件,就可以使用。如果找不到文件,您可以加载其他文件,例如
error.html

glob('/*.html')指的是web服务器文件系统根,而不是文档根的子目录。所有web服务器文件系统根都相似吗?im使用CPanelm我的观点是,每个主题都有单独的.html页面,这最终会导致维护噩梦。例如,如果你想重新设计网站的外观,现在你有数千个页面需要更改,该怎么办?这不好,根本上是有缺陷的。你会如何从不同的页面上搜索书籍?如果我在做这样的项目,我会写一个网页垃圾清理器来浏览网站,吸收所有的东西,将它放入数据库中,然后创建一个页面,该页面包含一个查询参数,如
somesite.com/books/?author=freud
,然后您只需使用GET操作创建一个表单,就可以完成所有设置。不要大惊小怪。另一个注意事项是,这允许您在搜索中具有0灵活性。表单的
方法
未设置,因此它将默认为
get
,而不是
post