Jump to content

echo $test with class


mrt003003

Recommended Posts

Hi there i just need to assign a class to my echoed vairable.

 

echo $test class="somecssclass";

 

Im sure im missing  some braces here or something but i cant seem to find it out. Heres the error: Parse error: syntax error, unexpected T_CLASS, expecting ',' or ';'

 

Please help

 

Thanks

Link to comment
Share on other sites

If you want to echo out a string, you can either concatenate it together using the '.' to stitch different parts of the string together, or you can use php's ability to interpolate (combine variables and string constants) together, replacing the variables.  I'm going to guess that what you want is something more like this:

 

echo $test . 'class="somecssclass"';

Link to comment
Share on other sites

So I'm guessing here that what you mean is that you have some text that should be inside some sort of html markup?  and you want this text to have a style applied?  I'm just guessing here because you've offered very little for anyone to understand what you're doing or why. 

 

If so, you need to apply the style to the html tag, which you're not doing.

 


$sometext = 'Hello phpfreaks';

echo '
' . $sometext . '';

 

 

Link to comment
Share on other sites

No problem.  In html there's a concept of 'block' vs. 'inline" elements.  Typically people apply the one that makes sense, although in css you can set the property to be what you want it to be when you apply a style.  So in  general, you should try and use the html element that makes sense for your content.  If it's a block of content, then use one of the block elements like a p or div.  If you need to style something inline, like one word in a sentence then you can use one of the built-ins like strong or b, or use span.

 

This might help you understand the concept better:  http://webdesign.about.com/od/htmltags/qt/block_vs_inline_elements.htm

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.