Jump to content


This topic is now archived and is closed to further replies.


Variables in HTML tags/ Php in header

Recommended Posts

I am trying to insert a variable directly into a line of HTML, with no spaces...

the line of code I've got looks like this:

$selectedshirtid = $info['shirt_id'];
echo "<DIV class=menuContainer id=menu'$selectedshirtid'Container>[/code]

but this outputs

<DIV class=menuContainer id=menu'3'Container>

It's not supposed  have the single quote around the variable...should look like this...

<DIV class=menuContainer id=menu3Container>

if I just put the php variable on it's own with no quotes..it doesn't read at all...

Also- can php be used in the HTML header? I can't think of why it wouldn't be able to...but for some reason I remember reading that it can't...

Share this post

Link to post
Share on other sites
Use curly braces around your variable:
[code]$selectedshirtid = $info['shirt_id'];
echo "<DIV class=\"menuContainer\" id=\"menu{$selectedshirtid}Container\">[/code]
Without the curly braces PHP will get confused. The curly braces are used to help php out.

and use quotes around your attributes values in your html tags.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.