mrlayance
mrlayance

Reputation: 663

Variable value is not being respected inside of a single quoted string

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

Answers (1)

NikiC
NikiC

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

Related Questions