If I want to use PHP to print some HTML, can I apply a class to it from CSS?
e.g.
ThanksPHP Code:<?php
print "
<table border cellpadding=3>
<tr>
<td class="tdclass">Type:</td>
<td>Name:</td>
<td>Address:</td>
<td>Telephone:</td>
</tr>";
?>
If I want to use PHP to print some HTML, can I apply a class to it from CSS?
e.g.
ThanksPHP Code:<?php
print "
<table border cellpadding=3>
<tr>
<td class="tdclass">Type:</td>
<td>Name:</td>
<td>Address:</td>
<td>Telephone:</td>
</tr>";
?>
Just solved it.
Had to put a \ before the "
doh!
I'm not entirely certain what you're asking. Are you trying to find out if a rule involving .tdclass would be applied? The answer's yes, and you could have just tried something simple (like changing text colour) to find out for yourself.
Rather than using print or echo to output large amounts of literal text, just drop out of PHP mode:
There's an error in the table start-tag, though the border attribute should be removed entirely and implemented using CSS. In addition, "tdclass" isn't a very good class name. Choose something that conveys what the class represents, rather than how it looks or what element it gets used with.Code:/* ... */ ?> <table border cellpadding=3> <tr> <td class="tdclass">Type:</td> <td>Name:</td> <td>Address:</td> <td>Telephone:</td> </tr> <?php /* ... */
Mike
One way to escape using the slash is to use single quotes for the php:
I also agree with Winter on two points. One, the border should be declared in the CSS. Two, if there's no PHP used in that block of HTML, drop out of PHP. Also, he has a point with the class name. But I'm not innocent of using vague class names, either, so I wont shove the idea down your throat. But it's smart to name it something more specific.PHP Code:<?php
print '
<table cellpadding="3">
<tr>
<td class="tdclass">Type:</td>
<td>Name:</td>
<td>Address:</td>
<td>Telephone:</td>
</tr>';
?>
Thou com'st in such a questionable shape
Hamlet, Act 1, Scene 4
Bookmarks