Results 1 to 4 of 4

Thread: Applying CSS to PHP

  1. #1
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Question Applying CSS to PHP

    If I want to use PHP to print some HTML, can I apply a class to it from CSS?

    e.g.
    PHP Code:
    <?php
    print "
    <table border cellpadding=3>
    <tr>
    <td class="
    tdclass">Type:</td> 
    <td>Name:</td>
    <td>Address:</td>
    <td>Telephone:</td>
    </tr>"

    ?>
    Thanks

  2. #2
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    Just solved it.

    Had to put a \ before the "

    doh!

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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:

    Code:
        /* ... */
    ?>
    <table border cellpadding=3>
        <tr>
            <td class="tdclass">Type:</td> 
            <td>Name:</td>
            <td>Address:</td>
            <td>Telephone:</td>
        </tr>
    <?php
        /* ... */
    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.
    Mike

  4. #4
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    One way to escape using the slash is to use single quotes for the php:

    PHP Code:
    <?php
    print '
    <table cellpadding="3">
    <tr>
    <td class="tdclass">Type:</td> 
    <td>Name:</td>
    <td>Address:</td>
    <td>Telephone:</td>
    </tr>'

    ?>
    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.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •