Jump to content

echo $test with class


mrt003003

Recommended Posts

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"';

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

 

 

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

Archived

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

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