Page 1 of 1
HTML OUTPUT / ECHO / END PHP
Posted: Thu Dec 04, 2003 8:09 pm
by ptysell
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.
Posted: Thu Dec 04, 2003 8:13 pm
by Chambrln
I do mine depending on how much html there is to display. If I have an elaborate table or row with tables in it I do what you have, but if it is just one cell or one row then I usually just echo it.
Posted: Thu Dec 04, 2003 9:33 pm
by d3ad1ysp0rk
i try to keep it all in php, and if you have large chunks of HTML, use here.doc
Posted: Fri Dec 05, 2003 3:10 am
by JayBird
Before Nay jumps in and gets all excited about HEREDOC, i'll mention it first
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;
Take a look at this link -
http://uk.php.net/manual/en/language.ty ... ax.heredoc
Mark[/url]
Posted: Fri Dec 05, 2003 2:36 pm
by BDKR
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.
Code: Select all
?>
yada yada yada yada <?php print $string; ?> yada yada yada
<?php
or
Code: Select all
?>
yada yada yada yada yada yada <?=$string ?> yada yada yada yada
<?php
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
Posted: Fri Dec 05, 2003 2:53 pm
by microthick
I guess I'm unpopular
For echoing small strings, I choose to go:
<?= $myVar ?>
For example, I might go:
<form name="update" action="<?= $_SERVER["PHP_SELF"] ?>" method="post">
Posted: Fri Dec 05, 2003 2:57 pm
by Draco_03
me too this is the exact same way i use..
Posted: Fri Dec 05, 2003 3:10 pm
by BDKR
I guess I'm unpopular right along with you guys.
We're now a club
Cheers,
BDKR
Posted: Fri Dec 05, 2003 8:38 pm
by Nay
Bech100 wrote:Before Nay jumps in and gets all excited about HEREDOC, i'll mention it first

[/url]

Never again Mark, never again

.
-Nay