Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.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_Regex_Time - Fatal编程技术网

数据库中使用的PHP正则表达式问题

数据库中使用的PHP正则表达式问题,php,regex,time,Php,Regex,Time,我是新来的,有一个问题。 我有两个带时间的输入框。我得到的值是3h 20m 31s。 如何将其转换为3:20:31,以便在数据库中使用?无需使用正则表达式。如果你有固定的格式,你可以这样做 $input = "3h 20m 31s"; $input = str_replace("h ",":",$input); $input = str_replace("m ",":",$input); $input = str_replace("s","",$input); 或者,如果您喜欢正则表达式: $

我是新来的,有一个问题。 我有两个带时间的输入框。我得到的值是3h 20m 31s。
如何将其转换为3:20:31,以便在数据库中使用?

无需使用正则表达式。如果你有固定的格式,你可以这样做

$input = "3h 20m 31s";
$input = str_replace("h ",":",$input);
$input = str_replace("m ",":",$input);
$input = str_replace("s","",$input);
或者,如果您喜欢正则表达式:

$input = "3h 20m 31s";
$regex = "/^\D*(\d+)\D*(\d+)\D*(\d+)\D*$/";
$matches = array();
preg_match($regex, $input,$matches);
echo implode(":",array_slice($matches,1))

您将使用哪种服务器端语言在数据库中写入值?实际上,它被用作一个fliter,因此其结果将用于mysql查询的WHERE语句您使用的是哪种类型的输入?标准文本输入或默认选择输入(您应该使用)?我不能使用默认选择输入,因为它是一个有390.000条记录的数据库!由于时间不同,我没有固定的格式,这只是一个例子。当有人只输入5s或4m 3s时会发生什么?它还能用吗?不行,那不行。还有其他条件可以更新答案吗?它们需要以h:m:s格式返回。我不知道,如果已经是这样了,如果其中一个没有给出,应该是00,那么34m 5将变成00:34:05