Here's my code:
$jsonData = file_get_contents('http://example.com/bin/serp.php?engine=google&phrase=$name');
It doesn't appear to be using $name
correctly. How would I add that variable into my string like I'm trying to do?
Here's my code:
$jsonData = file_get_contents('http://example.com/bin/serp.php?engine=google&phrase=$name');
It doesn't appear to be using $name
correctly. How would I add that variable into my string like I'm trying to do?
Change the single quotes to double quotes. PHP variables are not interpolated when in single quotes.
$jsonData = file_get_contents("http://example.com/bin/serp.php?engine=google&phrase=$name");
You can also use concatenation here:
$jsonData = file_get_contents('http://example.com/bin/serp.php?engine=google&phrase=' . $name);
Either change the single quotes around your string to double quotes:
"http://example.com/bin/serp.php?engine=google&phrase=$name"
Or use string concatenation with the .
operator:
'http://example.com/bin/serp.php?engine=google&phrase=' . $name
Both of these techniques are mentioned on PHP's Strings documentation.