Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php str_替换问题_Php_Str Replace - Fatal编程技术网

php str_替换问题

php str_替换问题,php,str-replace,Php,Str Replace,奇怪的是,我肯定错过了什么 $city = "vancouver"; $insert1 = "https://www.site.ca/buy/vancouver/28130965/"; $url2 = str_replace('/$city/','index.php?deal=',$insert1); 返回?您只能使用双引号。使用: str_replace("/$city/", 'index.php?deal=', $insert1); 或: 您使用的是单引号。使用双引号“。 s

奇怪的是,我肯定错过了什么

$city = "vancouver";

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

$url2 = str_replace('/$city/','index.php?deal=',$insert1);
返回?

您只能使用双引号。使用:

str_replace("/$city/", 'index.php?deal=', $insert1);
或:


您使用的是单引号。使用双引号
str_replace('/' . $city . '/', 'index.php?deal=', $insert1);