Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3779

Re: Embedding HTML Within a PHP Statement

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: Embedding HTML Within a PHP Statement
Date Mon, 14 Nov 2011 13:39:40 +0100
Organization A noiseless patient Spider
Lines 36
Message-ID <4EC10C0C.7000800@arnowelzel.de> (permalink)
References <mhg1c7p6qe5ng95rfiguu1b0tu18143m4a@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
Injection-Info mx04.eternal-september.org; posting-host="1gm8FlMTLcdkzSpiXSf0MA"; logging-data="8759"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9wTaSaDbJ+nRzu7YCxgQTQ5/RTL4q/Is="
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0
In-Reply-To <mhg1c7p6qe5ng95rfiguu1b0tu18143m4a@4ax.com>
Cancel-Lock sha1:kAB0BzwvEzAR9oqMdtSWkSa7boE=
Xref x330-a1.tempe.blueboxinc.net comp.lang.php:3779

Show key headers only | View raw


Call Me Tom, 2011-11-14 08:29:

> I was under the impression that a section of PHP code (the part
> between <?PHP and ?>) was independent of any other section of PHP
> code.  Today I found the following code in a working program:
> 
>    <?php if (!empty($error_message)) { ?>
>    <p class="error"><?php echo $error_message; ?></p>
>    <?php } ?>
> 
> This is the first time I have seen a section of PHP code end in the
> middle of a PHP statement and restart after some HTML was inserted.  I
> was surpised that the PHP interpreter was able to connect the two
> sections of PHP code.

Well - this is the way how PHP works. The interpreter will just output
all the stuff between ?> and <?php without interpreting it.

> My question is not how the interpreter does it (that's way beyond my
> level of knowledge) but rather 
>   1. Does this only work in special cases or does it work in all
> cases?

This works in all cases. In fact this is by design, how PHP works.

>   2. Is it considered good programming, bad programming or personal
> preference?

It depends on the situation. Usually it's easier to embed large HTML
fragments than to output every single line using echo or print.


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Embedding HTML Within a PHP Statement Call Me Tom <noemail@nowhere.com> - 2011-11-14 02:29 -0500
  Re: Embedding HTML Within a PHP Statement Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-11-14 11:10 +0100
    Re: Embedding HTML Within a PHP Statement Balazs Nadasdi <yitsushi@gmail.com> - 2011-11-14 05:07 -0800
      Re: Embedding HTML Within a PHP Statement Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-14 08:19 -0500
        Re: Embedding HTML Within a PHP Statement Balazs Nadasdi <yitsushi@gmail.com> - 2011-11-14 06:41 -0800
          Re: Embedding HTML Within a PHP Statement Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-14 13:59 -0500
            Re: Embedding HTML Within a PHP Statement Balazs Nadasdi <yitsushi@gmail.com> - 2011-11-14 11:41 -0800
              Re: Embedding HTML Within a PHP Statement Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-14 15:22 -0500
                Re: Embedding HTML Within a PHP Statement Balazs Nadasdi <yitsushi@gmail.com> - 2011-11-14 17:44 -0800
      Re: Embedding HTML Within a PHP Statement Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-11-14 14:29 +0100
      Re: Embedding HTML Within a PHP Statement houghi <houghi@houghi.org.invalid> - 2011-11-14 20:54 +0100
        Re: Embedding HTML Within a PHP Statement Michael Fesser <netizen@gmx.de> - 2011-11-14 21:47 +0100
        Re: Embedding HTML Within a PHP Statement Ross McKay <au.org.zeta.at.rosko@invalid.invalid> - 2011-11-16 09:15 +1100
  Re: Embedding HTML Within a PHP Statement Tim Streater <timstreater@greenbee.net> - 2011-11-14 10:39 +0000
    Re: Embedding HTML Within a PHP Statement Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-11-14 11:57 +0100
      Re: Embedding HTML Within a PHP Statement The Natural Philosopher <tnp@invalid.invalid> - 2011-11-14 11:49 +0000
      Re: Embedding HTML Within a PHP Statement Tim Streater <timstreater@greenbee.net> - 2011-11-14 12:30 +0000
        Re: Embedding HTML Within a PHP Statement Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-11-14 15:01 +0100
          Re: Embedding HTML Within a PHP Statement Tim Streater <timstreater@greenbee.net> - 2011-11-14 14:39 +0000
            Re: Embedding HTML Within a PHP Statement Michael Fesser <netizen@gmx.de> - 2011-11-14 18:07 +0100
            Re: Embedding HTML Within a PHP Statement Gregor Kofler <usenet@gregorkofler.com> - 2011-11-15 23:55 +0100
              Re: Embedding HTML Within a PHP Statement Tim Streater <timstreater@greenbee.net> - 2011-11-15 23:02 +0000
                Re: Embedding HTML Within a PHP Statement Gregor Kofler <usenet@gregorkofler.com> - 2011-11-16 00:06 +0100
                Re: Embedding HTML Within a PHP Statement Tim Streater <timstreater@greenbee.net> - 2011-11-16 10:10 +0000
                Re: Embedding HTML Within a PHP Statement Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-16 14:23 +0000
          Re: Embedding HTML Within a PHP Statement Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-14 14:18 -0500
        Re: Embedding HTML Within a PHP Statement Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-14 18:52 +0000
  Re: Embedding HTML Within a PHP Statement Arno Welzel <usenet@arnowelzel.de> - 2011-11-14 13:39 +0100
  Re: Embedding HTML Within a PHP Statement Gregor Kofler <usenet@gregorkofler.com> - 2011-11-14 13:54 +0100
  Re: Embedding HTML Within a PHP Statement Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-14 13:54 +0000
  Re: Embedding HTML Within a PHP Statement bobm3@worthless.info - 2011-11-14 21:15 -0500

csiph-web