-2

I want to add $destination in the url of the file_get_contents

$content = file_get_contents('https://googleapis.com/json?destinations=New+York+City,NY&units=imperial&origins=&key=AIzaSyDK4HhNWMzdCN5zDOJJI61BFJlKwhvpe4c');

to

$content = file_get_contents('https://googleapis.com/json?destinations=$destination&units=imperial&origins=&key=AIzaSyDK4HhNWMzdCN5zDOJJI61BFJlKwhvpe4c');
  • 1
    Ok, using which code? What doesn't work? Have you considered using `"` instead of `'` so `$destination` gets expanded? (It doesn't when using single quotes `'`) From the [manual](https://www.php.net/manual/en/language.types.string.php): "_Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings._" – brombeer Jul 13 '20 at 20:29

1 Answers1

-1

to evaluate variables inside a string you have to use double quotation marks instead of single. for example:

$name = "edris";
echo "Hello $name";

this code will work fine. becasue in this case we used " instead of '. I hope this can help.