Echoing a variable with a class

hey folks, i m new in php, i m echoing a a value with a css class. to wrap the class i wrapped it around p element. the class is printing the value but the element p is also printing along. here is my code

<?php "<p class="\\gt"> {$gt} </p>" ;?>

what am i missing?

why we made the class a variable ? $TotalClass ? now its printing the values but not with class property

“Generate the class within PHP”

You mean it changes depending on the value of $GrandTotal?

In that case, work it out beforehand (in PHP) and save it in a variable called something like $TotalClass.


<input type="text" readonly="readonly" class="<?php echo $TotalClass; ?>" value="<?php echo htmlentities($GrandTotal); ?>" />

i suppose the php echo data which make the input html class null. isn’t it? coz i wanna generate the class within php not out of php code. coz its not being applied. like that

can u provide me with a fixed example. i m new to this so everything is jumbled up

Make sure you use the dots Immerse used in his code to concatenate strings. The warning suggests you’re using comma’s, thus supplying different parameters for the htmlentities() function, which is not what you want.

i tried the first example. i m getting this error in the input field
<br /> <b>Warning</b>: htmlentities() [<a href=‘function.htmlentities’>function.htmlentities</a>]: charset `</p>’ not supported, assuming iso-8859-1 in <b>page.php</b> on line <b>214</b><br /> <p class=“total”>

still i am getting <p /> around the value echoed. here is the code

<input type="text" readonly="readonly"  value=<?php echo '<p class="total">',$GrandTotal, '</p>'; ?> />

An echo statement, and the quotes are incorrect:


<?php echo '<p class="gt">', $gt, '</p>' ;?>

(I also removed the \ before “gt” because it’s not needed)

The examples from Immerse in post #4 work perfectly if you copy/paste them correctly …

Why are you trying to put HTML in a textfield?

Maybe you should do something like this:


<input type="text" readonly="readonly" value="<?php echo htmlentities('<p class="total">' . $GrandTotal . '</p>'); ?>" />

However, if you simply want to change the style of the text in the textfield, you can add a class to the textfield itself:


<input type="text" readonly="readonly" clsas="total" value="<?php echo htmlentities($GrandTotal); ?>" />