Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何制作日期范围搜索功能_Php_Search_Date Range - Fatal编程技术网

Php 如何制作日期范围搜索功能

Php 如何制作日期范围搜索功能,php,search,date-range,Php,Search,Date Range,这是我的脚本,显示搜索框,用于使用关键字从csv文件中搜索数据 <?php $file = fopen('aws.csv', 'r'); $output =''; if (isset($_POST['searchVal'])) { $words = $_POST['searchVal']; $words = array(preg_replace("#[^0-9a-z]#"," ",$words)); $words = array_map('preg_quote', $words);

这是我的脚本,显示搜索框,用于使用关键字从csv文件中搜索数据

<?php
$file  = fopen('aws.csv', 'r');
$output ='';
if (isset($_POST['searchVal'])) {
$words = $_POST['searchVal'];

$words = array(preg_replace("#[^0-9a-z]#"," ",$words));

$words = array_map('preg_quote', $words);
// The argument becomes '/wii|guitar/i', which means 'wii or guitar, case-insensitive'
$regex = '/'.implode('|', $words).'/i';

while (($line = fgetcsv($file)) !== FALSE) {  
    list($name, $age, $hobbies) = $line;

    if(preg_match($regex, $age)) {
        $output .=  "$name, $age, $hobbies<br/>";
    }

    }
}       
?>

<form action="search1.php" method="post">
    <input type="text" name="search" placeholder="Search">
</form>

<?php echo $output; ?>


现在我想做一个范围搜索功能,例如我想搜索20150727-20150730之间的日期。。。20150727意味着2015年7月27日

转换\将cs导入db将使这一过程变得更加简单-这是一个option@Dagon无法…因为我的项目正在使用csv…:(您显示的唯一字段是姓名、年龄和爱好。您要搜索的日期值在哪里?这不是一种非常实用的存储方法…转换到数据库不会花费很长时间…即使是免费的云service@frymaster因为这是我的示例代码…让我们假设$age我改为$date…convert\import cs in to db将使这成为可能容易多了——这是一个好主意吗option@Dagon无法…因为我的项目正在使用csv…:(您显示的唯一字段是姓名、年龄和爱好。您要搜索的日期值在哪里?这不是一种非常实用的存储方法…转换到数据库不会花费很长时间…即使是免费的云service@frymaster因为这是我的示例代码…让我们假设我将$age更改为$date。。。