View Full Version : quick array/variable question

05-01-2006, 11:49 PM
I've got a few pages with different searches on them and a main page where I want to aggregate them all using includes. I have one section that parses the search term, another section that puts the urls for the 3 search pages in an array and another that displays the includes randomly. The problem I am having is that I can't add the search phrase on to the array properly and instead end up with "search.php?query=$search_phrase;" instead of the right value for $search_phrase, which would be whatever the user puts in.

$expl = explode("/",$HTTP_SERVER_VARS["REQUEST_URI"]);
$search_phrase = $expl[count($expl)-1];
print $search_phrase;


$include_files = array('search1.php?query=$search_phrase;','search2.php?query=$search_phrase;','search3.php?query=$se arch_phrase;',);


for ( $i = 0; $i < 3; $i++ )

05-02-2006, 12:15 AM
Anything in single quotes is treated as a literal, in short, you can't interpolate with single quotes, you'll have to use double quotes or concatenation:

$include_files = array("search1.php?query=$search_phrase;","search2.php?query=$search_phrase;","search3.php?query=$search_phrase;",);

$include_files = array('search1.php?query=' . $search_phrase . ';','search2.php?query=' . $search_phrase . ';','search3.php?query=' . $search_phrase . ';',);

05-02-2006, 12:23 AM
thank you!

05-02-2006, 12:46 AM
What you're doing won't work though. When you do an include, it isn't a HTTP request, so the $_GET superglobal isn't going to be populated.