here.doc

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

here.doc

Post by d3ad1ysp0rk »

how do you echo it without putting it in a variable first?
ie i usually use:

Code: Select all

$myvar = <<<M
HTML STUFF
M;

echo $myvar;
but now i'd like to just use it to echo HTML w/o escaping the quotes (in my attributes)..
is it..

Code: Select all

echo <<<a
HTML STUFF
a;
?

thanks
-justin
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

When I need to output lots of HTML, I just get out of php mode, then re-enter when I'm done.

ie.

Code: Select all

<?php

if ($var == $var2) &#123;
?>
   //all of my html
<?php
 &#125;

?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Yes that second example seems to be correct:
http://shat.net/php/notes/heredoc.php
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Personally I think embedding html in php scripts is doing it the wrong way round. Scripts should just define a bunch of output vars, then print them in an html template.

Business logic, then presentation, nice and separate...
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Yeah, I'm addicted to heredoc but I'm starting to go into what McGruff said. Sometimes people just miss a " and get a parse error and come running to me <_<.

Well, if it's your own project, blah, do what you want :lol:. If you're working in a group where you know the rest are non-PHP-ers then you might want to save the hassle. For me, it's because I'm publishing my CMS to the public and I'm sure every single one of them want to edit the HTML templates. Mixing PHP in them is just not an option.

-Nay
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

just try

Code: Select all

Print <<< END
//your code here, all html tags work.
END;
Post Reply