Noob - php works as .php but not when part of html

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Data Goob

    #16
    Re: Noob - php works as .php but not when part of html

    Geoff Berrow wrote:
    [color=blue]
    > I noticed that Message-ID: <nWYcd.686$ix2. 460@fe05.usenet server.com>
    > from Data Goob contained the following:
    >
    >[color=green]
    >>Well, now you've got my curiousity...
    >>
    >>Why is it a bad idea to intermingle PHP with HTML?[/color]
    >
    >
    > I don't believe it is, necessarily.
    >
    > But by default the resultant file has to be named <something>.p hp
    > whether it contains just raw php or a mixture of php and html.
    >[/color]
    Actually this is not true. I have several HTML files with PHP
    embedded. In fact they are not only with embedded PHP the PHP
    statement is a PHP include, and I have SSI's as well... with the
    ..html suffix.


    <HTML>
    blah blah blah...

    <?php include 'my-embedded-calendar.php' ?>

    more HTML...

    </HTML>

    So what it really boils down to is in getting Apache to see .html
    as something that can be interpreted as/with PHP. As a purist,
    this might seem a violation and comingling of two different things,
    but for me it is hybridization and the ability to component-ize
    my sites for easier maintenance. Is it right for all web work?
    Probably not appropriate in all situations, and may even create
    problems with other add-ons like templates, etc. I view templates
    as hybridization anyway, so for me the discussion is purely
    academic. Template integration reduces portability, so if this is
    the intent, don't do non-portable PHP/SSI/HTML/TEMPLATES/ETC.

    In the final analysis, it works beautifully for my sites...


    <HTML>

    blah blah blah...

    <!--include virtual="my-included-banner.html-->

    <?php include 'my-embedded-calendar.php' ?>

    more HTML...

    </HTML>

    Regards,

    -DG-

    Comment

    • Anonymous

      #17
      Re: Noob - php works as .php but not when part of html

      Data Goob wrote:[color=blue]
      >
      > Well, now you've got my curiousity...
      >
      > Why is it a bad idea to intermingle PHP with HTML?[/color]

      It isn't.

      But when you do so you should name the file *.php, so that the server
      knows it has to parse the file through php.

      Alternativly you could tell the server to parse every file through php
      but *that* is not a good idea. If all of your pages contain php it
      wouldn't make any difference but if this is not the case the server goes
      through quite a bit of unnecessary overhead.

      That might not matter on your personal server that is only used for
      testing, but no provider is going to configure his server like that
      because less overhead means they can put more customers on one server.
      So if you want your pages to run on any provider's server without having
      to change them you should go with the usual file naming.

      In other words: If it contains php name it *.php.

      Bye!

      Comment

      • Michael Fesser

        #18
        Re: Noob - php works as .php but not when part of html &lt;found the answer&gt;

        .oO(Alvaro G. Vicario)
        [color=blue]
        >*** dogu escribió/wrote (Sun, 17 Oct 2004 10:32:42 -0400):[color=green]
        >> Seems my confusion was thinking you could co-mingle php and html code in
        >> files with html extensions. If I change the extension to .php it works
        >> like a charm![/color]
        >
        >There's no point in feeding *all* pages to the PHP interpreter. The *.php
        >extension is the way to parse only pages that contain code.[/color]

        I consider it bad style to have both .html and .php appear in URLs.

        On Apaches it's possible to parse some files with PHP and deliver others
        directly, while keeping _all_ URLs consistent with the extension .html
        (MultiViews).

        Micha

        Comment

        • John Dunlop

          #19
          URI suffixes (was: Noob - php works as .php but not when part of html &lt;found the answer&gt;)

          Michael Fesser wrote:
          [color=blue]
          > I consider it bad style to have both .html and .php appear in URLs.[/color]

          Is there a reason for either?
          [color=blue]
          > On Apaches it's possible to parse some files with PHP and deliver others
          > directly, while keeping _all_ URLs consistent with the extension .html[/color]

          '.html' and other URI suffixes are redundant, contrary to
          the principle of keeping URIs short and rememberable, and
          deleterious to URI persistency. As a rule then it's best to
          chop the wee nasties off.
          [color=blue]
          > (MultiViews).[/color]

          Right.

          Slainte! & HAGW!

          --
          Jock

          Comment

          • Michael Fesser

            #20
            Re: URI suffixes (was: Noob - php works as .php but not when part of html &lt;found the answer&gt;)

            .oO(John Dunlop)
            [color=blue]
            >Michael Fesser wrote:
            >[color=green]
            >> I consider it bad style to have both .html and .php appear in URLs.[/color]
            >
            >Is there a reason for either?[/color]

            Not really. I use either .html or no extension at all.
            [color=blue]
            >'.html' and other URI suffixes are redundant, contrary to
            >the principle of keeping URIs short and rememberable, and
            >deleterious to URI persistency.[/color]

            There's at least one point: Unexperienced users might expect web
            addresses to start with 'www.' and end on '.html'. Sure we know that
            both are not really necessary ...
            [color=blue]
            >As a rule then it's best to
            >chop the wee nasties off.[/color]

            That's what I will do in my next (testing) project, but for other
            reasons. In short: With a URL like www.example.com/foo the server will
            automatically decide according to the Accept header whether to send HTML
            or XHTML back to the client. But I still want to be able to override the
            content negotiation and force a particular content type if necessary, be
            it for testing, for validation or simply for providing the same resource
            in different formats (PDF for example). So to override the CN mechanismn
            I would simply request /foo.html, /foo.xhtml or /foo.pdf if available.

            That's just the very basic idea, I still have to think about some things
            and implementation issues.

            Micha

            Comment

            • John Dunlop

              #21
              Re: URI suffixes (was: Noob - php works as .php but not when part of html &lt;found the answer&gt;)

              Michael Fesser wrote:
              [color=blue]
              > There's at least one point: Unexperienced users might expect web
              > addresses to start with 'www.' and end on '.html'. Sure we know that
              > both are not really necessary ...[/color]

              Fair enough. Although with the myriad different suffixes
              out there today, '.php', '.asp', '.pl', '.cf' to name but a
              few, I'm still unconvinced that surfers, inexperienced or
              not, expect URIs to end in '.html'.

              Also, I am seeing more and more URIs without suffixes on
              television. Rightpondians can see the BBC's abbreviated
              URIs, e.g. www.bbc.co.uk/weather -- that one's unfortunately
              a redirection; hey, the beeb can't get it right all the
              time, can they? If the big guns publish sensible URIs, the
              practice will hopefully catch on soon.

              [about chopping off URI suffixes]
              [color=blue]
              > That's what I will do in my next (testing) project, but for other
              > reasons. In short: With a URL like www.example.com/foo the server will
              > automatically decide according to the Accept header whether to send HTML
              > or XHTML back to the client. But I still want to be able to override the
              > content negotiation and force a particular content type if necessary, be
              > it for testing, for validation or simply for providing the same resource
              > in different formats (PDF for example). So to override the CN mechanismn
              > I would simply request /foo.html, /foo.xhtml or /foo.pdf if available.[/color]

              Sounds good to me.
              [color=blue]
              > That's just the very basic idea, I still have to think about some things
              > and implementation issues.[/color]

              This might be of value:



              Slainte!

              --
              Jock

              Comment

              • Michael Fesser

                #22
                Re: URI suffixes (was: Noob - php works as .php but not when part of html &lt;found the answer&gt;)

                .oO(John Dunlop)
                [color=blue]
                >This might be of value:
                >
                >http://groups.google.com/groups?th=36072a520721e723[/color]

                Yep. Thanks.

                Micha

                Comment

                Working...