HTML OUTPUT / ECHO / END PHP
Moderator: General Moderators
HTML OUTPUT / ECHO / END PHP
what is better in the long run for convience and compatibility,
PHP
?>
HTML
<?
PHP
or
echo HTML
Just wondering. I mostly use echo but i do not know if that is the correct thing to do.
PHP
?>
HTML
<?
PHP
or
echo HTML
Just wondering. I mostly use echo but i do not know if that is the correct thing to do.
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
Before Nay jumps in and gets all excited about HEREDOC, i'll mention it first 
you can do somthing like this
Take a look at this link - http://uk.php.net/manual/en/language.ty ... ax.heredoc
Mark[/url]
you can do somthing like this
Code: Select all
echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;Mark[/url]
Another thing to consider is that switching context back to Apache for a string is twice as fast as
. However, there can be some readability issues here depending on how and where it's used. What I like to do is if I have a ton of lines of HTML with php vars sprinkled here and there is just escape php (?>) and then context switch back into php just to echo (or print) those vars.
or
That second example is extemely un-popular (like using '#' for comments (?)) and it does cause problems (somehow) if you are using XML. I don't know the details of that one though.
Cheers,
BDKR
Cheers,
BDKR
Code: Select all
echo 'string';Code: Select all
?>
yada yada yada yada <?php print $string; ?> yada yada yada
<?phpCode: Select all
?>
yada yada yada yada yada yada <?=$string ?> yada yada yada yada
<?phpCheers,
BDKR
Cheers,
BDKR
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC