tags:

views:

68

answers:

2

Right now I'm assigning HTML to a variable the usual way:

$var = <<<END
<blah>...</blah>
END;

The big disadvantage is that my IDE won't treat this as HTML, and so it won't highlight the code. Is there a way to do it that will keep the HTML outside of the <?php ?> tags so that code highlighting will work?

+1  A: 

I try to avoid this as much as possible by using a template engine such as Smarty -> http://www.smarty.net/

Jacob
Yes, a template engine is definitely how you want to handle HTML contents in general.
msakr
PHP is already a templating engine in itself. Smarty is overrated.
Lotus Notes
+2  A: 

If you're printing, you could always just exit PHP and go back in whenever you like:

<?php

function print_header() {
    ?>
    <html>
        <head>

        </head>
        <body>

    <?php
}

function print_footer() {
    ?>

        </body>
    </html>
    <?php
}

print_header();
print_footer();

Alternatively, you could use buffers to use that technique to assign them to variables:

<?php

function print_header() {
    ob_start();
    ?>
    <html>
        <head>

        </head>
        <body>

    <?php
    return ob_get_clean();
}

function print_footer() {
    ob_start();
    ?>

        </body>
    </html>
    <?php
    return ob_get_clean();
}

echo print_header();
echo print_footer();
msakr
+1 PHP is a templating langugage. Use it, don't fight it! When you say `$var= 'a load of HTML';` or `echo '<a>some html with insecure $interpolations</a>';` you are doing it wrong!
bobince