Page 1 of 1

echo keyword and text

Posted: Sat May 30, 2009 10:42 pm
by Tsongkie
This is a newbie question

Code: Select all

 
$keyword= $links[rand(0,sizeof($links)-1)];
 $keywordwithlink= '<a href="index.php?Query=$keyword"> $keyword </a>'   ;
 echo $keywordwithlink;
 
Problem is it shows "$keyword" as "$keyword" and not the variable. Any help?

Re: echo keyword and text

Posted: Sat May 30, 2009 10:54 pm
by SidewinderX

Code: Select all

$keywordwithlink= "<a href=\"index.php?Query=$keyword\"> $keyword </a>";
You have to use double quotes (and thus escape the inner quotes).

Re: echo keyword and text

Posted: Sat May 30, 2009 10:58 pm
by Tsongkie
Parse error: syntax error, unexpected T_STRING

I think it because I have double quotes with this as well:

Code: Select all

"index.php?Query=$keyword"

Re: echo keyword and text

Posted: Sat May 30, 2009 11:06 pm
by SidewinderX
Not sure if you noticed but I escaped the inner double quotes with a backslash. Take a look the "Variable parsing" section here: http://us.php.net/language.types.string It should clear some things up.