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

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

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

    I'm missing something and need a push in the right direction.
    If I create a php file with the following content, and call it via a
    browser, it works as expected.
    <?php
    echo "hello world";
    ?>

    If I embed the same thing in a simple HTML file, I get nothing.
    <html>
    <body>
    <?php>
    echo "Hello world";
    ?>
    </body>
    </html>

    I'm running
    Mandrake 10.0
    Apache 2
    PHP 4
    The php_mod is loaded for Apache.
    I did the install for both Apache and PHP via Mandrakes built in rpm
    management system.

    TIA for any tips.

    Doug
  • Geoff Berrow

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

    I noticed that Message-ID:
    <zqOdnaUmufZv0u _cRVn-uA@metrocastcab levision.com> from dogu contained
    the following:
    [color=blue]
    >I'm missing something and need a push in the right direction.
    >If I create a php file with the following content, and call it via a
    >browser, it works as expected.
    ><?php
    >echo "hello world";
    >?>
    >
    >If I embed the same thing in a simple HTML file, I get nothing.
    ><html>
    ><body>
    ><?php>
    >echo "Hello world";
    >?>
    ></body>
    ></html>[/color]

    Unless you have configured Apache otherwise, the file must end in .php

    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • Geoff Berrow

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

      I noticed that Message-ID: <r8k4n05dtp2vmt ofcqcnht8tbgbd0 s6k3a@4ax.com>
      from Geoff Berrow contained the following:
      [color=blue][color=green]
      >>If I embed the same thing in a simple HTML file, I get nothing.
      >><html>
      >><body>
      >><?php>
      >>echo "Hello world";
      >>?>
      >></body>
      >></html>[/color]
      >
      >Unless you have configured Apache otherwise, the file must end in .php[/color]

      Oops. Just noticed an erroneous '>'

      try

      <html>
      <body>
      <?php
      echo "Hello world";
      ?>
      </body>
      </html>

      --
      Geoff Berrow (put thecat out to email)
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • dogu

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

        Geoff Berrow wrote:[color=blue]
        > I noticed that Message-ID: <r8k4n05dtp2vmt ofcqcnht8tbgbd0 s6k3a@4ax.com>
        > from Geoff Berrow contained the following:
        >
        >[color=green][color=darkred]
        >>>If I embed the same thing in a simple HTML file, I get nothing.
        >>><html>
        >>><body>
        >>><?php>
        >>>echo "Hello world";
        >>>?>
        >>></body>
        >>></html>[/color]
        >>
        >>Unless you have configured Apache otherwise, the file must end in .php[/color]
        >
        >
        > Oops. Just noticed an erroneous '>'
        >
        > try
        >
        > <html>
        > <body>
        > <?php
        > echo "Hello world";
        > ?>
        > </body>
        > </html>
        >[/color]
        Thanks, but what I posted was a type - in my actual code, the <?php line
        is identical to yours.

        What do you mean 'unless you have configured Apache otherwise...'? I
        bet that's the problem but don't know what to configure.

        Any tips would be appreciated.

        Doug

        Comment

        • Brad Kent

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

          Even with HTML intermingled amongst the PHP code, it's still a .php
          file.
          rename it whatever.php.

          Of course you could tell apache to parse .html files as .php, but that
          would be very bad advice.

          dogu <dfinnerathome@ netscape.net> wrote in message news:<zqOdnaUmu fZv0u_cRVn-uA@metrocastcab levision.com>.. .[color=blue]
          > I'm missing something and need a push in the right direction.
          > If I create a php file with the following content, and call it via a
          > browser, it works as expected.
          > <?php
          > echo "hello world";
          > ?>
          >
          > If I embed the same thing in a simple HTML file, I get nothing.
          > <html>
          > <body>
          > <?php>
          > echo "Hello world";
          > ?>
          > </body>
          > </html>
          >
          > I'm running
          > Mandrake 10.0
          > Apache 2
          > PHP 4
          > The php_mod is loaded for Apache.
          > I did the install for both Apache and PHP via Mandrakes built in rpm
          > management system.
          >
          > TIA for any tips.
          >
          > Doug[/color]

          Comment

          • dogu

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

            Geoff Berrow wrote:[color=blue]
            > I noticed that Message-ID: <r8k4n05dtp2vmt ofcqcnht8tbgbd0 s6k3a@4ax.com>
            > from Geoff Berrow contained the following:
            >
            >[color=green][color=darkred]
            >>>If I embed the same thing in a simple HTML file, I get nothing.
            >>><html>
            >>><body>
            >>><?php>
            >>>echo "Hello world";
            >>>?>
            >>></body>
            >>></html>[/color]
            >>
            >>Unless you have configured Apache otherwise, the file must end in .php[/color]
            >
            >
            > Oops. Just noticed an erroneous '>'
            >
            > try
            >
            > <html>
            > <body>
            > <?php
            > echo "Hello world";
            > ?>
            > </body>
            > </html>
            >[/color]
            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!

            Take care.

            Doug

            Comment

            • Lüpher Cypher

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

              dogu wrote:[color=blue]
              > Geoff Berrow wrote:
              >[color=green]
              >> I noticed that Message-ID: <r8k4n05dtp2vmt ofcqcnht8tbgbd0 s6k3a@4ax.com>
              >> from Geoff Berrow contained the following:
              >>
              >>[color=darkred]
              >>>> If I embed the same thing in a simple HTML file, I get nothing.
              >>>> <html>
              >>>> <body>
              >>>> <?php>
              >>>> echo "Hello world";
              >>>> ?>
              >>>> </body>
              >>>> </html>
              >>>
              >>>
              >>> Unless you have configured Apache otherwise, the file must end in .php[/color]
              >>
              >>
              >>
              >> Oops. Just noticed an erroneous '>'
              >>
              >> try
              >>
              >> <html>
              >> <body>
              >> <?php
              >> echo "Hello world";
              >> ?>
              >> </body>
              >> </html>
              >>[/color]
              > 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!
              >
              > Take care.
              >
              > Doug[/color]

              Bet you can set up the server to treat html files as php :)

              Comment

              • Alvaro G. Vicario

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

                *** dogu escribió/wrote (Sun, 17 Oct 2004 10:32:42 -0400):[color=blue]
                > 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.


                --
                -+ Álvaro G. Vicario - Burgos, Spain
                +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
                ++ Las dudas informáticas recibidas por correo irán directas a la papelera
                -+ I'm not a free help desk, please don't e-mail me your questions
                --

                Comment

                • Data Goob

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

                  Did you check your web server configuration?

                  In Apache on Linux, you might add:

                  AddType application/x-httpd-php .php .html

                  This will allow you to include PHP in your HTML as

                  <HTML>

                  blah blah blah...

                  <?php

                  php stuff blah blah blah

                  ?>

                  </HTML>


                  You may have to have

                  AddOutputFilter INCLUDES .shtml
                  AddOutputFilter INCLUDES .html

                  added as well, but don't have the time to test. These turn on SSI's on
                  your pages, but I don't know if they affect embedded PHP or not. At
                  any rate I have both on my server and they work.

                  -DG-

                  dogu wrote:
                  [color=blue]
                  > Geoff Berrow wrote:
                  >[color=green]
                  >> I noticed that Message-ID: <r8k4n05dtp2vmt ofcqcnht8tbgbd0 s6k3a@4ax.com>
                  >> from Geoff Berrow contained the following:
                  >>
                  >>[color=darkred]
                  >>>> If I embed the same thing in a simple HTML file, I get nothing.
                  >>>> <html>
                  >>>> <body>
                  >>>> <?php>
                  >>>> echo "Hello world";
                  >>>> ?>
                  >>>> </body>
                  >>>> </html>
                  >>>
                  >>>
                  >>> Unless you have configured Apache otherwise, the file must end in .php[/color]
                  >>
                  >>
                  >>
                  >> Oops. Just noticed an erroneous '>'
                  >>
                  >> try
                  >>
                  >> <html>
                  >> <body>
                  >> <?php
                  >> echo "Hello world";
                  >> ?>
                  >> </body>
                  >> </html>
                  >>[/color]
                  > 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!
                  >
                  > Take care.
                  >
                  > Doug[/color]

                  Comment

                  • Michiel de Roo

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

                    Data Goob wrote:[color=blue]
                    > Did you check your web server configuration?
                    >
                    > In Apache on Linux, you might add:
                    >
                    > AddType application/x-httpd-php .php .html[/color]

                    You probably want to put this in a .htaccess, so that it is NOT server-wide.

                    Comment

                    • Data Goob

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

                      Right Roo, good point.

                      You could also do the Virtual host thang as well but I haven't tested, so I'm
                      unsure as to the rightness, truth, etc.

                      -DG-

                      Michiel de Roo wrote:[color=blue]
                      > Data Goob wrote:
                      >[color=green]
                      >> Did you check your web server configuration?
                      >>
                      >> In Apache on Linux, you might add:
                      >>
                      >> AddType application/x-httpd-php .php .html[/color]
                      >
                      >
                      > You probably want to put this in a .htaccess, so that it is NOT
                      > server-wide.[/color]

                      Comment

                      • Geoff Berrow

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

                        I noticed that Message-ID:
                        <hamdnUs_3t8MHe _cRVn-rA@metrocastcab levision.com> from dogu contained
                        the following:
                        [color=blue]
                        >
                        >What do you mean 'unless you have configured Apache otherwise...'? I
                        >bet that's the problem but don't know what to configure.[/color]

                        What Brad said...

                        --
                        Geoff Berrow (put thecat out to email)
                        It's only Usenet, no one dies.
                        My opinions, not the committee's, mine.
                        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                        Comment

                        • Data Goob

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

                          Well, now you've got my curiousity...

                          Why is it a bad idea to intermingle PHP with HTML?

                          Wasn't that the intent of PHP in the first place?

                          FWIW I'm not arguing one way or the other, just interested
                          in your opinion(s) .

                          -DG-

                          Geoff Berrow wrote:
                          [color=blue]
                          > I noticed that Message-ID:
                          > <hamdnUs_3t8MHe _cRVn-rA@metrocastcab levision.com> from dogu contained
                          > the following:
                          >
                          >[color=green]
                          >>What do you mean 'unless you have configured Apache otherwise...'? I
                          >>bet that's the problem but don't know what to configure.[/color]
                          >
                          >
                          > What Brad said...
                          >[/color]

                          Comment

                          • Michael Vilain

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

                            In article <nWYcd.686$ix2. 460@fe05.usenet server.com>,
                            Data Goob <datagoob@hotma il.com> wrote:
                            [color=blue]
                            > Well, now you've got my curiousity...
                            >
                            > Why is it a bad idea to intermingle PHP with HTML?
                            >
                            > Wasn't that the intent of PHP in the first place?
                            >
                            > FWIW I'm not arguing one way or the other, just interested
                            > in your opinion(s) .
                            >
                            > -DG-
                            >
                            > Geoff Berrow wrote:
                            >[color=green]
                            > > I noticed that Message-ID:
                            > > <hamdnUs_3t8MHe _cRVn-rA@metrocastcab levision.com> from dogu contained
                            > > the following:
                            > >
                            > >[color=darkred]
                            > >>What do you mean 'unless you have configured Apache otherwise...'? I
                            > >>bet that's the problem but don't know what to configure.[/color]
                            > >
                            > >
                            > > What Brad said...
                            > >[/color][/color]

                            I've read many opinions on this. It all seems to revolve around the
                            scope of the project you're working on. Medium to large projects tend
                            to bog down with the code that generates the site and the actual HTML
                            itself. My own project is now to the point that I need to refactor it
                            to strip out embedded HTML and use a templating system instead, just to
                            make it easier to understand and support and grow.

                            I'm now seeing the result of forgetting stuff I coded months ago and
                            having to refamiliarize myself with it when I go back and update it.
                            I'm leaning toward a OOP page display class with templates.

                            In any case, as an old procedure coder who first learned FORTRAN in the
                            early 1970's and never used C very much (automatic variables really
                            confused me initially), it's been interesting having to rethink this
                            project.

                            Now I see why the database weenies like using the database as a
                            repository for the datastructures and business logic (i.e. Oracle's
                            triggers or MySQL's stored procedures in the next release) and the
                            application does the data capture, validation, and presentation.

                            --
                            DeeDee, don't press that button! DeeDee! NO! Dee...



                            Comment

                            • Geoff Berrow

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

                              I noticed that Message-ID: <nWYcd.686$ix2. 460@fe05.usenet server.com>
                              from Data Goob contained the following:
                              [color=blue]
                              >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.

                              --
                              Geoff Berrow (put thecat out to email)
                              It's only Usenet, no one dies.
                              My opinions, not the committee's, mine.
                              Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                              Comment

                              Working...