weixin_33738578 2017-11-11 10:07 采纳率: 0%
浏览 14

Ajax搜索POST到php

I need some help with refining my current search.

I have folder with images that are named as:

20171116-category_title.jpg       (where first number is date yyyymmdd)

My current search looks like this:

<?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);
?>

And this works just fine but...

  1. I would like to limit search only to part of .jpg name that contains "title" behind underscore " _ " and after that (if possible) to expand search to:

  2. To make double search if AJAX POST sends following format: abc+xyz where delimiter "+" practicaly means 2 queries.

    First part is (abc) which targets "category" that stands between minus and underscore and second part of query (xyz) (which is basically my first question) only among previously found (category) answers.

    Your tips are more than welcome! Thank you!

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 通过STM32F4实现智能清洁小车,要求用到三个以上传感器
      • ¥15 perl代码解释说明
      • ¥15 列举 五阶幻方 有多少种
      • ¥15 请教一下能人在VS中调用MATLAB绘制动态驻波
      • ¥15 VB.NET如何调用Microsoft Excel?(WPS存在时)
      • ¥15 KUKA机器人EtherNetIP通讯配置教程
      • ¥15 VB6.0如何模拟键盘组合按键
      • ¥15 python怎么替换这个word里边内容
      • ¥15 做谷歌浏览器插件的时候,怎么在background.js中优先执行其他.js文件里面函数呀?
      • ¥15 win 10家庭版非管理员账户如何获取管理权限