php str_replace问题

mrl*_*nce 2 php str-replace

奇怪的是,我一定是在遗漏一些东西.

$city = "vancouver";

$insert1 = "https://www.site.ca/buy/vancouver/28130965/";    

$url2 = str_replace('/$city/','index.php?deal=',$insert1);
Run Code Online (Sandbox Code Playgroud)

https://www.site.ca/buy/vancouver/28130965/返回?

Nik*_*kiC 6

您只能用双引号插入变量.使用:

str_replace("/$city/", 'index.php?deal=', $insert1);
Run Code Online (Sandbox Code Playgroud)

要么:

str_replace('/' . $city . '/', 'index.php?deal=', $insert1);
Run Code Online (Sandbox Code Playgroud)