我需要一些帮助来完善我目前的搜索。Ajax搜索POST到php
我有一个图片文件夹命名为:
20171116-category_title.jpg (where first number is date yyyymmdd)
我目前的搜索是这样的:
<?php
// string to search in a filename.
if(isset($_POST['question'])){
$searchString = $_POST['question'];
}
// image files in my/dir
$imagesDir = '';
$files = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
// 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.
echo json_encode($filesFound, JSON_UNESCAPED_UNICODE);
?>
这工作得很好,但...
我想限制搜索仅限于包含“title”后面的下划线“_”的.jpg名称的一部分,之后(如果可能的话e)将搜索扩展为:
如果AJAX POST发送以下格式,则进行双重搜索:abc + xyz其中分隔符“+”实际上表示2个查询。
第一部分是(abc),它只针对查询(xyz)(这基本上是我的第一个问题)的减号和下划线以及第二部分之间的“类别”,仅在之前找到的(类别)答案中。
您的提示比欢迎! 谢谢!
你解决这个问题,没有我的回答帮助? –
对不起,谢谢你。我离开了我的工作,所以我没有实现你的解决方案,但我看到它会好的。如果因为任何原因我再次被卡住生病如果我可以尝试联系你? 再一次,谢谢你! – vixus