Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正则表达式对我来说一直是一门火箭科学。有谁能告诉我如何编写 preg_replace 将 2013-12-12 12-00-00 转换为 2013-12-12 12:00:00。我尝试使用
preg_replace("/-(?=\s)/", ":", $string)
我知道这是不正确的,因为它没有提供所需的输出。
只需寻找一个空格,后跟三对用连字符分隔的数字,然后用另一个空格和三对用冒号分隔符替换:
$datetime = preg_replace('/ (\d\d)-(\d\d)-(\d\d)$/'," $1:$2:$3",$datetime);