Dilema, Blocks of HTML within PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • beezmnet@gmail.com

    #1

    Dilema, Blocks of HTML within PHP

    Well...

    I need to be able to have a large block of HTML code inside a PHP
    document, assign it a variable, and use other variables, functions, and
    objects within the HTML code still.

    Clarification:

    I have the following code (as an example):

    $variable = <<<HTML
    <table>
    <tr><td>$text </td></tr>
    <tr><td>echo $config->getBlah()</td></tr>
    </table>
    HTML;

    I need to be able to do that ^, that actual code wouldn't work, but it
    is an example of what I need to do. I have tried searching for the <<<
    operator, or whatever it is, the problem is most search utilities won't
    recognize <<<, so it is really really hard to search and find answers
    about it, I can't find anything about it on the php manual, I'm falling
    onto a last resort by posting on some forums to see if anyong is able
    to help me.

    So question being really:
    Is there a way I can split that so it recognizes those lines as PHP and
    not part of the block of HTML code
    OR
    Is there another method that I can use to achieve this same effect ?

    I have to be able to keep the block of code together, not seperating
    each line into a variable declaration. such as:
    $var = "<tr><td>" . $text . "</td></tr>";
    $var .= "<tr><td>" . echo $config->getBlah(); . "</td></tr>";
    Do NOT want to do that.

    So if anyone has any ideas/solutions, please, please let me know :)

    Thanks.

  • beezmnet@gmail.com

    #2
    Re: Dilema, Blocks of HTML within PHP

    For anyone else that may be interested, I was able to get an answer to
    my question.
    Here would be the syntax of what I need to do:

    $variable =<<<HTML
    <table>
    <tr><td>{$text} </td></tr>
    <tr><td>{$confi g->getBlah()}</td></tr>
    </table>
    HTML;

    Comment

    • chernyshevsky@hotmail.com

      #3
      Re: Dilema, Blocks of HTML within PHP

      The ability to insert code into HTML is the raison d'etre of PHP.

      <table>
      <tr><td><?=$tex t?></td></tr>
      <tr><td><?=$con fig->getBlah()?></td></tr>
      </table>

      Comment

      Working...