0

<html>
<head>
<title>test page</title>
</head>
<body>

<?php

echo "<h1>hello there</h1>";

?>

</body>
</html>


or,


<?php

echo <<<EOT
<html>
<head>
<title>test page</title>
</head>
<body>

EOT;

echo "<h1>hello there</h1>";


echo "</body></html>";

?>

5
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by almostbob
1

Hi! Welcome to DW!!

For us Web Developers, I think the best approach would be like this:

<html>
<body>
<h1><?php echo "Hello there!"; ?></h1>


</body>
</html>

Doing this kind of approach could be more coding rather than echo-ing it all. But the advantage of doing this is making it more easier to edit the HTML tags by means of any HTML editor(Dreamweaver for example). Making it more convenient for development :)

Hope this helps! :D

0

EDIT: Sory, missed the heredoc tag. Both are correct. It is just a question of style. Either write html tags like in former case or echo them lake in later. ignore my statement below

The former is the correct way. Between the <?php and ?> tags only valid PHP sysntax can be included, otherwise you will get errors.

Edited by broj1: n/a

0

Just to add my views of how I do it in a web app that runs on the intranet server. I use the later aprach. I have one PHP class that generates html code for each page on the site. In this class properties are elements of the page (head, body, headings paragraphs, included headers, footers, menus...). Each property can be used with default value or changed by methods. This way all pages have the same look and feel and still be customized programatically if necessary. The benefit is that I have total control over the html code from PHP, depending of user input, user rights and roles, session values etc. The downside might be performance, since server has to generate html for each page, but in my case this is not an issue. Another downside is that you can not use Dreamweaver or Frontpage or similar visual editor. Again not an issue for me since html is always generated by one PHP class.

0

My general view is that use <?php ?> as little as possible and use proper Html code to generate as much as possible...
It's really pain to modify if the code get's any more complicated

1

whatever works for YOU
the typical 'hello world' to a rdbms require different appproaches different code
echo is appropriate for a single line
heredoc for blocks of text

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.