Jump to content


Variables in HTML tags/ Php in header

  • Please log in to reply
1 reply to this topic

#1 jwwceo

  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 29 August 2006 - 06:22 PM

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>

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

#2 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 August 2006 - 06:24 PM

Use curly braces around your variable:
$selectedshirtid = $info['shirt_id'];
echo "<DIV class=\"menuContainer\" id=\"menu{$selectedshirtid}Container\">
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.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users