jwwceo Posted August 29, 2006 Share Posted August 29, 2006 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: [code]$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... Quote Link to comment https://forums.phpfreaks.com/topic/19047-variables-in-html-tags-php-in-header/ Share on other sites More sharing options...
wildteen88 Posted August 29, 2006 Share Posted August 29, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/19047-variables-in-html-tags-php-in-header/#findComment-82365 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.