在 php 中将反斜杠替换为正斜杠和 str_replace()

php
2022-08-30 10:02:21

我有以下网址:

$str = "http://www.domain.com/data/images\flags/en.gif";

我用来尝试用正斜杠替换反斜杠:str_replace

$str = str_replace('/\/', '/', $str);

它似乎不起作用,这是结果:

http://www.domain.com/data/images\flags/en.gif

答案 1

你必须放置双反斜杠

$str = str_replace('\\', '/', $str);

答案 2
$str = str_replace('\\', '/', $str);

推荐