Results 1 to 4 of 4

Thread: add code font size in the php echo

  1. #1
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default add code font size in the php echo

    Good day!

    I have a pure php code, so my table was in echo and I want to change the font and font-size of text in table header but when I put thid code:
    PHP Code:
    echo "<font size="18" face='Arial'>";
    echo 
    "<table>";

    and 
    at the lower part i close it
    echo "</table>";
    echo 
    "</font>"
    It only take effect in the text outside the table. and when I try to put it on the <table> It doesn't take effect.

    Thank you in advance

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That's not pure PHP code. It's PHP and HTML. The font tag is deprecated in some HTML, discouraged in all. Why use it in code that is output by PHP? Why use echo to output an entire table? Good PHP practice is to drop out of PHP, write the table in ordinary HTML, then resume PHP:

    PHP Code:
    <?php
    //some preparatory PHP stuff here
    ?>
    <table>
    <tr>
    <td></td>
    </tr>
    </table>
    <?php
    //continue on with more PHP
    ?>
    That way both single and double quotes (if either are used) will maintain their literal meaning in the HTML code without needing to be escaped. If you need something resolved from PHP, you may put it inline in the table:

    PHP Code:
    <?php
    //some preparatory PHP stuff here
    ?>
    <table>
    <tr>
    <td><?php echo $myvar?></td>
    </tr>
    </table>
    <?php
    //continue on with more PHP
    ?>
    That's assuming that $myvar was previously defined.

    Anyways, the final determination of the font used in the table are its td's, and the font should be set in an external stylesheet, so you could have:

    PHP Code:
    <?php
    //some preparatory PHP stuff here
    ?>
    <table class="myclass">
    <tr>
    <td><?php echo $myvar?></td>
    </tr>
    </table>
    <?php
    //continue on with more PHP
    ?>
    And for the font you want, this rule should be in the page's external stylesheet:

    Code:
    table.myclass td {
    	font: normal 48px arial, sans-serif;
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    If you still want to use your code, be sure to escape:
    PHP Code:
    echo "<font size=\"18\" face='Arial'>";
    echo 
    "<table>";

    //and at the lower part i close it

    echo "</table>";
    echo 
    "</font>"
    This would only fix the php error btw.
    This wont change the font size, and it is deprecated anyways, use CSS! (see jscheuer's post.)
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Sometimes there are some rather dynamic tables, which I use php to generate and display. For example display certain user stats, but only display the table when the user is logged in and if the user is of such a rank then generate a heavily abridged table with different columns. For this reason I sometimes do not see a way to easily escape out of php to dynamically generate the HTML.

    in jscheuer's line font: normal 48px arial, sans-serif; the 48px is the size equivalent of font size = "18". sans-serif is a backup font in case the visitor's browser does not recognize arial. It is a good idea and common practice to have a secondary font available.
    To choose the lesser of two evils is still to choose evil. My personal site

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
  •