php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #16663 Different syntax for embedding HTML in PHP
Submitted: 2002-04-17 12:18 UTC Modified: 2002-04-17 17:39 UTC
From: bill at bwi dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.2.0 OS: Linux
Private report: No CVE-ID: None
 [2002-04-17 12:18 UTC] bill at bwi dot com
The following can be confusing to read:

html>
<br>This is plain HTML
<?
    echo "<br>This is a PHP Block";
    ?>
    <br>This is raw html text embedded in PHP.
    <?
    echo "<br>This is the same outer PHP block";
?>
<br>This is more plain HTML
</html>

The following is easier to read, at least for me,
with a C programming background:

html>
<br>This is plain HTML
<?
    echo "<br>This is a PHP Block";
    HTML
        {
        <br>This is raw html text embedded in PHP.
        }
    echo "<br>This is the same outer PHP block";
?>
<br>This is more plain HTML
</html>

This would make HTML a reserved word that would turn off
the PHP parser within the following set of braces, or if
braces aren't present, until the next semicolon.  The
advantage of this style is it makes it easier to see the
underlying block structure of the PHP code, yet avoids
having to use echo or print to output chunks of HTML code.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-17 12:24 UTC] bill at bwi dot com
Missed the opening < on <html>
 [2002-04-17 12:29 UTC] bill at bwi dot com
I can't seem to figure out how to edit the submission,
so I can't fix the missing < on <html>
 [2002-04-17 16:01 UTC] mfischer@php.net
What's wrong with

<?php
  echo "Ene mene foo<br />\n";
  echo <<<HTML
<hr>
Some more html
<hr>
HTML

?>

Any, unlikely SUCH a change is done. Ever. :-)
 [2002-04-17 17:00 UTC] bill at bwi dot com
There is nothing wrong with your alternative except that I can't find info about the contstruct

echo <<<HTML
some more html
HTML

in the online documentation.  Should I add this to the notes regarding "Example 5-2. Advanced escaping" on

http://www.php.net/manual/en/language.basic-syntax.php

in the online documentation, since this is apparently an additional method for disabling the PHP parser ?

NOTE: I did try to search the online documentation for "<<<" without any result. I also spoke to a PHP programmer with considerably more experience than me, who was also unfamiliar with this construct.
 [2002-04-17 17:39 UTC] bill at bwi dot com
Well, I found another bug report #8685 which clued me in about where to find the documentation for this type of
construct, which is a "heredoc" text entry.  Interestingly,
the other report was also from someone trying to write readable, block-structured code, and was also classified as bogus.  I guess us old guys who were around when Pascal was invented just have some weird ideas about how code should be organized to be "people" friendly.
 [2002-04-23 15:17 UTC] tbrinkman at cinci dot rr dot com
Don't think of it as including HTML in PHP.  Think of it as including PHP in HTML.  That way you have your block-level delimiters as the standard PHP start/end tags.

Whether this is a problem is completely dependant on your point of view.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 20:01:32 2024 UTC