SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    FBI secret agent digitman's Avatar
    Join Date
    Sep 2004
    Location
    Work
    Posts
    697
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    creating html code inside PHP code

    I need to put some html code in my php code that creates a table if an If statement returns true.I'll have to print the values of variabls into the <td>s.But its a complete pain to write down each line of html (even the npsp; s)inside echo commands.How can I write the code in HTML but still print the values of the variables inside the table and continue with my code after the html code ends?

  2. #2
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Escape PHP.

    <?php
    //code here
    if () {
    ?>
    <html>
    </html>
    <?php
    }
    ?>

    Get it?

  3. #3
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php 
    if ($x true){
    ?>
    <!-- table code here -->
    <?php ?>

  4. #4
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    victoria
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are two other ways:

    1)

    PHP Code:
    <?php
    $stuff 
    '<table code>';
    $stuff .= '<more table code>';
    $stuff .= '<more table code>';
    $stuff .= '<more table code>';
    $stuff .= '<more table code>';

    if (
    $x true) {
        echo(
    "$stuff");
    }

    ?>
    2)

    PHP Code:
    <?php

    $tablecode 
    = <<<EOTABLE
    <table code here>
    <more table code here>
    <more table code here>
    <more table code here>
    EOTABLE;

    if (
    $x true) {
        echo(
    "$tablecode");
    }

    ?>
    hope this helps you. Use double quotes for the first example if you are include variables. Heredoc (second example) automatically includes all variables inside it.

  5. #5
    FBI secret agent digitman's Avatar
    Join Date
    Sep 2004
    Location
    Work
    Posts
    697
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    $tablecode 
    = <<<EOTABLE
    <table code here>
    <more table code here>
    <more table code here>
    <more table code here>
    EOTABLE;

    if (
    $x true) {
        echo(
    "$tablecode");
    }

    ?>

    I like that example.Do you have any links where I can read more about it?

  6. #6
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    victoria
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Research heredoc at php.net.

  7. #7
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •