Reputation: 663
When I try to use the $city
value in a string, it is not working.
$city = "vancouver";
$insert1 = "https://www.example.com/buy/vancouver/28130965/";
$url2 = str_replace('/$city/', 'index.php?deal=', $insert1);
Output:
https://www.example.com/buy/vancouver/28130965/
Upvotes: 1
Views: 283
Reputation: 101946
You can interpolate variables only in double quotes. Use:
str_replace("/$city/", 'index.php?deal=', $insert1);
Or:
str_replace('/' . $city . '/', 'index.php?deal=', $insert1);
Upvotes: 6