echo keyword and text

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

Post Reply
Tsongkie
Forum Newbie
Posts: 13
Joined: Sun Feb 01, 2009 6:51 pm

echo keyword and text

Post 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?
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Re: echo keyword and text

Post 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).
Tsongkie
Forum Newbie
Posts: 13
Joined: Sun Feb 01, 2009 6:51 pm

Re: echo keyword and text

Post 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"
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Re: echo keyword and text

Post 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.
Post Reply