Jump to content

Variables in HTML tags/ Php in header


jwwceo

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:

[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...
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.