Re: [PHP] Couple of beginner questions



At 4:16 PM -0500 1/10/09, Paul M Foster wrote:
And let me present an alternative perspective. Never do something like:

<?php echo 'Hellow world'; ?>

Let Apache (or whatever) interpret HTML as HTML, and don't make it
interpret PHP code as HTML.

Instead, do:

<h1>Hello world</h1>

If you're going to use PHP in the middle of a bunch of HTML, then only
use it where it's needed:

<h1>Hello <?php echo $name; ?></h1>

The contents of the PHP $name variable can't be seen by the HTML, which
is why you need to enclose it in a little PHP "island". Naturally, if
you're going to put PHP code in the middle of a HTML page, make the
extension PHP. Otherwise, Apache will not interpret the PHP code as PHP
(unless you do some messing with .htaccess or whatever). It's just
simplest to call a file something.php if it has PHP in it.

Paul
--
Paul M. Foster

Paul:

I agree with you. My example was not well thought out. My point was not to mix style elements with data. I should have said:

I would consider the following"bad practice":

<?php echo("<h1>$whatever</h1>"); ?>

Whereas, the following I would consider "good practice".

<h1><?php echo("$whatever"); ?></h1>

Thanks for keeping me honest.

Cheers,

tedd


--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
.



Relevant Pages

  • Re: PHP5 IIS Setup
    ... If there were any html tags, ... Incidentally I'm using Apache 2, ... You haven't added a type association so Apache knows to use PHP to process ... it not processing PHP files. ...
    (alt.php)
  • Re: Content negotiation in Apache
    ... >Someone already mentioned the rewriting rules which will work for you. ... Sorry I hadn't posted anything in awhile, but Apache and I move ... The other is that I'm learning PHP and did not originally have the ... and got 600 visitors this December, and the page ends in ".html" and now ...
    (RedHat)
  • Re: PHP-Yes, HTML-No --- Why?
    ... Surely a dynamic web server should appear exactly the same as a static one - all files that contain HTML when viewed should be called ... If you know how, say, the PHP apache module works, you'll see that the hit is ... Apache was designed to do just this. ...
    (comp.lang.php)
  • Re: How do we get there from here?
    ... > then sub the whole of that generated markup into the template? ... layed out on the fly, a simple IMG tag, or even an entire HTML document. ... PHP scripting provides 10 times the features of both of these ... idea as tokens can eliminate a huge amount of maintance, ...
    (comp.databases.pick)
  • Re: query string passing woes........ help... please....
    ... |> | offer any help other than saying that my validation could be FAR more ... I'm a total newbie at php. ... The easiest way for you would be to make the html form called form.php ... $_SESSION array using the same names. ...
    (alt.php)