用 preg_match 替换时间字符串中的点

replacing a dot in a time string with preg_match

我正在尝试用“18:00”和“18:00/23:00”替换时间字符串,例如:“18.00”或“18.00/23.00”。

现在我已经做了一些东西,但是它没有用,而且我对此也不是很有经验

preg_replace("/\d{1,2}.\d{1,2}/",":","18.00/23.00");

添加捕获括号并转义圆点:

echo preg_replace("/(\d{1,2})\.(\d{1,2})/",":","18.00/23.00");
                    ^       ^^ ^       ^

PHP demo

</code>和<code>backreferences that point to the contents captured with capturing groups

您可以使用 str_replace 代替

str_replace(".", ":",$your_date);