Page 1 of 1

Combine a variable with a url

Posted: Tue Apr 03, 2007 11:06 am
by ojsimon
hi
i am trying to do this code but in the middle of the url i would like to put my variable
$file=file_get_contents("http://www.google.com/search?&q=n93+amazon.com&btnI");
how do i do this
Thanks

Posted: Tue Apr 03, 2007 11:11 am
by Oren

Code: Select all

$file=file_get_contents("http://www.go{$my_var}ogle.com/search?&q=n93+amazon.com&btnI"); 
Put {$my_var} wherever you wish within the URL.

Posted: Tue Apr 03, 2007 3:29 pm
by RobertGonzalez
An alternative way to do this is:

Code: Select all

<?php
$file=file_get_contents('http://www.google.com/search?&q=n93+amazon.com&btnI&my_variable=' . $my_variable_value);
?>
Concatenated strings are minutely faster than parsed strings. Not much to worry about in small situation, but if the need for the app ever grows... well it is better to have it handled up front, no?

Posted: Tue Apr 03, 2007 3:49 pm
by feyd
Last chance to stop duplicating threads of yours ojsimon.