HTML OUTPUT / ECHO / END PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ptysell
Forum Commoner
Posts: 34
Joined: Tue Dec 02, 2003 9:27 pm
Location: USC

HTML OUTPUT / ECHO / END PHP

Post 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.
Chambrln
Forum Commoner
Posts: 43
Joined: Tue Dec 02, 2003 10:45 am
Location: Oregon

Post 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.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

i try to keep it all in php, and if you have large chunks of HTML, use here.doc
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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]
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Another thing to consider is that switching context back to Apache for a string is twice as fast as

Code: Select all

echo 'string';
. 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
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

I guess I'm unpopular :P

For echoing small strings, I choose to go:

<?= $myVar ?>

For example, I might go:

<form name="update" action="<?= $_SERVER["PHP_SELF"] ?>" method="post">
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

me too this is the exact same way i use..
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

I guess I'm unpopular right along with you guys.

We're now a club :!:

Cheers,
BDKR
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Bech100 wrote:Before Nay jumps in and gets all excited about HEREDOC, i'll mention it first :)
[/url]
Image Never again Mark, never again Image.

-Nay
Post Reply