Combine a variable with a url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
ojsimon
Forum Newbie
Posts: 24
Joined: Sat Mar 31, 2007 5:01 am

Combine a variable with a url

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Last chance to stop duplicating threads of yours ojsimon.
Locked