mrt003003 Posted April 7, 2011 Share Posted April 7, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/233009-echo-test-with-class/ Share on other sites More sharing options...
gizmola Posted April 7, 2011 Share Posted April 7, 2011 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"'; Quote Link to comment https://forums.phpfreaks.com/topic/233009-echo-test-with-class/#findComment-1198373 Share on other sites More sharing options...
mrt003003 Posted April 7, 2011 Author Share Posted April 7, 2011 Hi there and thanks for the reply. Thats fixed the error but the class="somecssclass" is simply echoed after the text variable and is not actually formating the text. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/233009-echo-test-with-class/#findComment-1198377 Share on other sites More sharing options...
gizmola Posted April 7, 2011 Share Posted April 7, 2011 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 . ''; Quote Link to comment https://forums.phpfreaks.com/topic/233009-echo-test-with-class/#findComment-1198382 Share on other sites More sharing options...
mrt003003 Posted April 7, 2011 Author Share Posted April 7, 2011 Yes thats it exactly! I was beginning to think it would have had to be in a div. Im sorry if i seemed a bit vague Thank you very much for your help. Quote Link to comment https://forums.phpfreaks.com/topic/233009-echo-test-with-class/#findComment-1198390 Share on other sites More sharing options...
gizmola Posted April 7, 2011 Share Posted April 7, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/233009-echo-test-with-class/#findComment-1198392 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.