PHP:将时间字符串00:00:00替换为00:00

时间:2014-02-09 20:38:32

标签: php string replace

我有一个巨大的字符串,这是一个摘录:

$str = "time1, 12:05:00, time2, 02:25:00, time3, 11:00:00";

我希望得到这个输出,因为秒将永远是00:

time1, 12:05, time2, 02:25, time3, 11:00

到目前为止,这是我的代码:

$str = str_replace(':00', "", $str);

但它没有给我我期望的输出(仅参见11)

time1, 12:05, time2, 02:25, time3, 11

如何在PHP中完成此操作?

提前致谢

1 个答案:

答案 0 :(得分:2)

在不知道你必须处理的真正字符串的情况下,我们只能给出模糊的答案。这是我的:

<?php
$str = 'time1, 12:05:00, time2, 02:25:00, time3, 11:00:00';
echo preg_replace('/(\d{2}:\d{2}):00/', '${1}', $str);
?>