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

用户名

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

$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中完成此操作?

提前致谢

lu

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章