PHP in HTML simple test fail

Discussion in 'HTML' started by James, Dec 24, 2010.

  1. James

    James Guest

    I'm trying to embed simple PHP in HTML.
    as follows:

    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <html>
    <head></head>
    <body class="page_bg">
    <?php echo <p>Hello World</p>
    Today is: <? print(Date("l, F jS, Y")); ?>.
    </body>
    </html>

    --- This doesn't work either--

    <?php
    $today = date("F j, Y");
    PRINT "$today";
    ?>

    The 'Hello World' and 'Today is:' display as expected, but the date part
    does not display.
    I have tried Echo in place of print, same problem. All examples I've found
    are using the same syntax.

    What am I missing?
    Any suggestions appreciated.
     
    James, Dec 24, 2010
    #1
    1. Advertising

  2. James

    James Guest

    "Sherm Pendley" <> wrote in message
    news:...
    > "James" <> writes:
    >
    >> <?php echo <p>Hello World</p>

    >
    > You're missing a ?> here.
    >
    > sherm--
    >
    > --
    > Sherm Pendley
    > <http://camelbones.sourceforge.net>
    > Cocoa Developer
    >


    Ok I have simplified it.

    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <html>
    <head></head>
    <body class="page_bg">
    <?php echo <p>Hello World</p>; ?>
    <? $today = date("F j, Y"); ?>
    <? PRINT "$today"; ?>
    ?>
    ?>
    </body>
    </html>

    Same result, no date.
     
    James, Dec 24, 2010
    #2
    1. Advertising

  3. On 24/12/10 19:12, James wrote:
    > I'm trying to embed simple PHP in HTML.
    > as follows:
    >
    > <html>
    > <head>
    > <title>PHP Test</title>
    > </head>
    > <body>
    > <html>
    > <head></head>
    > <body class="page_bg">
    > <?php echo <p>Hello World</p>


    Terminate php encapsulation with "?>"

    > Today is: <? print(Date("l, F jS, Y")); ?>.


    use "date" not "Date"
    encapsulate php with "<?php ?>" and not "<? ?>"

    > </body>
    > </html>


    > --- This doesn't work either--
    >
    > <?php
    > $today = date("F j, Y");
    > PRINT "$today";


    try "print" and not "PRINT"

    > ?>
    >
    > The 'Hello World' and 'Today is:' display as expected, but the date part
    > does not display.
    > I have tried Echo in place of print, same problem. All examples I've found
    > are using the same syntax.


    try "echo" and not "Echo"

    > What am I missing?
    > Any suggestions appreciated.


    Try this exactly as I have typed it:

    <?php echo date(DATE_RFC2822); ?>

    if that works, try this, again exactly as I have typed it:

    <?php echo date("F j, Y"); ?>

    Apologies if you didn't actually type things the way you said you did,
    but I'm assuming that you've taken care to accurately report the
    commands that aren't working including capitalisation.

    Rgds

    Denis McMahon
     
    Denis McMahon, Dec 24, 2010
    #3
  4. James

    James Guest

    "Denis McMahon" <> wrote in message
    news:4d14f810$0$31536$...
    > On 24/12/10 19:12, James wrote:
    >> I'm trying to embed simple PHP in HTML.
    >> as follows:
    >>
    >> <html>
    >> <head>
    >> <title>PHP Test</title>
    >> </head>
    >> <body>
    >> <html>
    >> <head></head>
    >> <body class="page_bg">
    >> <?php echo <p>Hello World</p>

    >
    > Terminate php encapsulation with "?>"
    >
    >> Today is: <? print(Date("l, F jS, Y")); ?>.

    >
    > use "date" not "Date"
    > encapsulate php with "<?php ?>" and not "<? ?>"
    >
    >> </body>
    >> </html>

    >
    >> --- This doesn't work either--
    >>
    >> <?php
    >> $today = date("F j, Y");
    >> PRINT "$today";

    >
    > try "print" and not "PRINT"
    >
    >> ?>
    >>
    >> The 'Hello World' and 'Today is:' display as expected, but the date part
    >> does not display.
    >> I have tried Echo in place of print, same problem. All examples I've
    >> found
    >> are using the same syntax.

    >
    > try "echo" and not "Echo"
    >
    >> What am I missing?
    >> Any suggestions appreciated.

    >
    > Try this exactly as I have typed it:
    >
    > <?php echo date(DATE_RFC2822); ?>
    >
    > if that works, try this, again exactly as I have typed it:
    >
    > <?php echo date("F j, Y"); ?>
    >
    > Apologies if you didn't actually type things the way you said you did,
    > but I'm assuming that you've taken care to accurately report the
    > commands that aren't working including capitalisation.
    >
    > Rgds
    >
    > Denis McMahon
    >

    This does not work:
    <?php echo date(DATE_RFC2822); ?>

    Here is the test file live http://www.hepptech.com/phptest.htm
     
    James, Dec 24, 2010
    #4
  5. On Fri, 24 Dec 2010 13:49:57 -0600, James wrote:

    > This does not work:
    ><?php echo date(DATE_RFC2822); ?>
    >
    > Here is the test file live http://www.hepptech.com/phptest.htm


    What assurance do we have that php is parsing .htm files?
     
    Allodoxaphobia, Dec 24, 2010
    #5
  6. On 24/12/10 19:49, James wrote:
    > "Denis McMahon" <> wrote in message
    > news:4d14f810$0$31536$...
    >> On 24/12/10 19:12, James wrote:
    >>> I'm trying to embed simple PHP in HTML.
    >>> as follows:
    >>>
    >>> <html>
    >>> <head>
    >>> <title>PHP Test</title>
    >>> </head>
    >>> <body>
    >>> <html>
    >>> <head></head>
    >>> <body class="page_bg">
    >>> <?php echo <p>Hello World</p>

    >>
    >> Terminate php encapsulation with "?>"
    >>
    >>> Today is: <? print(Date("l, F jS, Y")); ?>.

    >>
    >> use "date" not "Date"
    >> encapsulate php with "<?php ?>" and not "<? ?>"
    >>
    >>> </body>
    >>> </html>

    >>
    >>> --- This doesn't work either--
    >>>
    >>> <?php
    >>> $today = date("F j, Y");
    >>> PRINT "$today";

    >>
    >> try "print" and not "PRINT"
    >>
    >>> ?>
    >>>
    >>> The 'Hello World' and 'Today is:' display as expected, but the date part
    >>> does not display.
    >>> I have tried Echo in place of print, same problem. All examples I've
    >>> found
    >>> are using the same syntax.

    >>
    >> try "echo" and not "Echo"
    >>
    >>> What am I missing?
    >>> Any suggestions appreciated.

    >>
    >> Try this exactly as I have typed it:
    >>
    >> <?php echo date(DATE_RFC2822); ?>
    >>
    >> if that works, try this, again exactly as I have typed it:
    >>
    >> <?php echo date("F j, Y"); ?>
    >>
    >> Apologies if you didn't actually type things the way you said you did,
    >> but I'm assuming that you've taken care to accurately report the
    >> commands that aren't working including capitalisation.
    >>
    >> Rgds
    >>
    >> Denis McMahon
    >>

    > This does not work:
    > <?php echo date(DATE_RFC2822); ?>
    >
    > Here is the test file live http://www.hepptech.com/phptest.htm


    Is your browser set up to parse php in htm files?

    I received the following:

    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <html>
    <head></head>
    <body class="page_bg">
    <?php echo date(DATE_RFC2822); ?>

    <?php echo <p>Hello World</p>; ?>
    <? $today = date("F j, Y"); ?>
    <? print "$today"; ?>
    ?>
    ?>
    </body>
    </html>

    If this had been parsed server side by a php processor, I would not have
    seen any of the php commands.

    I suspect that you need to call the file phptest.php, and you need to
    sort out some errors.

    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <html>
    <head></head>
    <body class="page_bg">
    <?php echo date(DATE_RFC2822); ?>

    <?php echo "<p>Hello World</p>"; ?>
    <?php $today = date("F j, Y"); ?>
    <?php echo "<p>$today</p>"; ?>

    </body>
    </html>
     
    Denis McMahon, Dec 24, 2010
    #6
  7. James wrote:
    > I'm trying to embed simple PHP in HTML.
    > as follows:
    >
    > <html>
    > <head>
    > <title>PHP Test</title>
    > </head>
    > <body>
    > <html>
    > <head></head>
    > <body class="page_bg">
    > <?php echo<p>Hello World</p>


    should be:

    <?php echo '<p>Hello World</p>' ?>

    or

    <?php echo "<p>Hello World</p>" ?>

    > Today is:<? print(Date("l, F jS, Y")); ?>.
    > </body>
    > </html>
    >
    > --- This doesn't work either--
    >
    > <?php
    > $today = date("F j, Y");
    > PRINT "$today";
    > ?>
    >
    > The 'Hello World' and 'Today is:' display as expected, but the date part
    > does not display.
    > I have tried Echo in place of print, same problem. All examples I've found
    > are using the same syntax.
    >
    > What am I missing?
    > Any suggestions appreciated.
    >
    >


    1. Does your server support PHP? Test by creating a text file named:
    "test.php" with content:
    <?php phpinfo() ?>

    Up load to server then test url "www.example.com/test.php", of course
    use your domain name. If you don't see the PHP information table then
    your server does not support PHP.

    2. What was the name of your file? Here a URL would have helped. was it
    something.php most servers are configured to parse php scripts with the
    "php" extension.



    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Dec 24, 2010
    #7
  8. James

    James Guest

    "Jonathan N. Little" <> wrote in message
    news:if2ucr$knn$-september.org...
    > James wrote:
    >> I'm trying to embed simple PHP in HTML.
    >> as follows:
    >>
    >> <html>
    >> <head>
    >> <title>PHP Test</title>
    >> </head>
    >> <body>
    >> <html>
    >> <head></head>
    >> <body class="page_bg">
    >> <?php echo<p>Hello World</p>

    >
    > should be:
    >
    > <?php echo '<p>Hello World</p>' ?>
    >
    > or
    >
    > <?php echo "<p>Hello World</p>" ?>
    >
    >> Today is:<? print(Date("l, F jS, Y")); ?>.
    >> </body>
    >> </html>
    >>
    >> --- This doesn't work either--
    >>
    >> <?php
    >> $today = date("F j, Y");
    >> PRINT "$today";
    >> ?>
    >>
    >> The 'Hello World' and 'Today is:' display as expected, but the date part
    >> does not display.
    >> I have tried Echo in place of print, same problem. All examples I've
    >> found
    >> are using the same syntax.
    >>
    >> What am I missing?
    >> Any suggestions appreciated.
    >>
    >>

    >
    > 1. Does your server support PHP? Test by creating a text file named:
    > "test.php" with content:
    > <?php phpinfo() ?>
    >
    > Up load to server then test url "www.example.com/test.php", of course use
    > your domain name. If you don't see the PHP information table then your
    > server does not support PHP.
    >
    > 2. What was the name of your file? Here a URL would have helped. was it
    > something.php most servers are configured to parse php scripts with the
    > "php" extension.
    >
    >
    >
    > --
    > Take care,
    >
    > Jonathan
    > -------------------
    > LITTLE WORKS STUDIO
    > http://www.LittleWorksStudio.com
    >


    Yes the server supports PHP, we have used form mailing php scripts for
    years.
    phptest.php is another test file -- try it, it works perfect.

    I'll have to understand the parsing matter better.
     
    James, Dec 24, 2010
    #8
  9. Denis McMahon wrote:
    >> > Today is:<? print(Date("l, F jS, Y")); ?>.

    > use "date" not "Date"


    PHP function names are case-insensitive so that is not his problem

    DaTe("l, F jS, Y") would have worked.

    > encapsulate php with "<?php ?>" and not"<? ?>"


    Depends, server may have short tags enabled, and therefore either would
    be valid.

    I suspect the OP does not have PHP support or is not naming the file
    correctly to be parsed as PHP.

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Dec 24, 2010
    #9
  10. James wrote:
    > "Denis McMahon"<> wrote in message
    > news:4d14f810$0$31536$...
    >> On 24/12/10 19:12, James wrote:
    >>> I'm trying to embed simple PHP in HTML.
    >>> as follows:
    >>>
    >>> <html>
    >>> <head>
    >>> <title>PHP Test</title>
    >>> </head>
    >>> <body>
    >>> <html>
    >>> <head></head>
    >>> <body class="page_bg">
    >>> <?php echo<p>Hello World</p>

    >>
    >> Terminate php encapsulation with "?>"
    >>
    >>> Today is:<? print(Date("l, F jS, Y")); ?>.

    >>
    >> use "date" not "Date"
    >> encapsulate php with "<?php ?>" and not"<? ?>"
    >>
    >>> </body>
    >>> </html>

    >>
    >>> --- This doesn't work either--
    >>>
    >>> <?php
    >>> $today = date("F j, Y");
    >>> PRINT "$today";

    >>
    >> try "print" and not "PRINT"
    >>
    >>> ?>
    >>>
    >>> The 'Hello World' and 'Today is:' display as expected, but the date part
    >>> does not display.
    >>> I have tried Echo in place of print, same problem. All examples I've
    >>> found
    >>> are using the same syntax.

    >>
    >> try "echo" and not "Echo"
    >>
    >>> What am I missing?
    >>> Any suggestions appreciated.

    >>
    >> Try this exactly as I have typed it:
    >>
    >> <?php echo date(DATE_RFC2822); ?>
    >>
    >> if that works, try this, again exactly as I have typed it:
    >>
    >> <?php echo date("F j, Y"); ?>
    >>
    >> Apologies if you didn't actually type things the way you said you did,
    >> but I'm assuming that you've taken care to accurately report the
    >> commands that aren't working including capitalisation.
    >>
    >> Rgds
    >>
    >> Denis McMahon
    >>

    > This does not work:
    > <?php echo date(DATE_RFC2822); ?>
    >
    > Here is the test file live http://www.hepptech.com/phptest.htm
    >
    >


    Just what I thought, rename your file phptest.php and see if it works.
    Also fix your quotes as I showed you in another post.

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Dec 24, 2010
    #10
  11. James

    James Guest

    "Jonathan N. Little" <> wrote in message
    news:if2v65$neh$-september.org...
    > James wrote:
    >> "Denis McMahon"<> wrote in message
    >> news:4d14f810$0$31536$...
    >>> On 24/12/10 19:12, James wrote:
    >>>> I'm trying to embed simple PHP in HTML.
    >>>> as follows:
    >>>>
    >>>> <html>
    >>>> <head>
    >>>> <title>PHP Test</title>
    >>>> </head>
    >>>> <body>
    >>>> <html>
    >>>> <head></head>
    >>>> <body class="page_bg">
    >>>> <?php echo<p>Hello World</p>
    >>>
    >>> Terminate php encapsulation with "?>"
    >>>
    >>>> Today is:<? print(Date("l, F jS, Y")); ?>.
    >>>
    >>> use "date" not "Date"
    >>> encapsulate php with "<?php ?>" and not"<? ?>"
    >>>
    >>>> </body>
    >>>> </html>
    >>>
    >>>> --- This doesn't work either--
    >>>>
    >>>> <?php
    >>>> $today = date("F j, Y");
    >>>> PRINT "$today";
    >>>
    >>> try "print" and not "PRINT"
    >>>
    >>>> ?>
    >>>>
    >>>> The 'Hello World' and 'Today is:' display as expected, but the date
    >>>> part
    >>>> does not display.
    >>>> I have tried Echo in place of print, same problem. All examples I've
    >>>> found
    >>>> are using the same syntax.
    >>>
    >>> try "echo" and not "Echo"
    >>>
    >>>> What am I missing?
    >>>> Any suggestions appreciated.
    >>>
    >>> Try this exactly as I have typed it:
    >>>
    >>> <?php echo date(DATE_RFC2822); ?>
    >>>
    >>> if that works, try this, again exactly as I have typed it:
    >>>
    >>> <?php echo date("F j, Y"); ?>
    >>>
    >>> Apologies if you didn't actually type things the way you said you did,
    >>> but I'm assuming that you've taken care to accurately report the
    >>> commands that aren't working including capitalisation.
    >>>
    >>> Rgds
    >>>
    >>> Denis McMahon
    >>>

    >> This does not work:
    >> <?php echo date(DATE_RFC2822); ?>
    >>
    >> Here is the test file live http://www.hepptech.com/phptest.htm
    >>
    >>

    >
    > Just what I thought, rename your file phptest.php and see if it works.
    > Also fix your quotes as I showed you in another post.
    >
    > --
    > Take care,
    >
    > Jonathan
    > -------------------
    > LITTLE WORKS STUDIO
    > http://www.LittleWorksStudio.com
    >


    Jonathan

    I had the phptest.php file all along, but I was trying to get the php code
    to work embeded in a .HTM page.
    So, must I use a .PHP page suffix for any page containg php?

    I was under the impression that I could use php in a .HTM page as suggested
    here http://www.ntchosting.com/php/php-in-html.html

    I'll be reviewing the replies to this post again to be sure I understand.
     
    James, Dec 24, 2010
    #11
  12. James

    idle Guest

    On Fri, 24 Dec 2010 14:47:13 -0600, James wrote in alt.html:

    > "Jonathan N. Little" <> wrote in message
    > news:if2v65$neh$-september.org...
    >> James wrote:
    >>> "Denis McMahon"<> wrote in message
    >>> news:4d14f810$0$31536$...
    >>>> On 24/12/10 19:12, James wrote:
    >>>>> I'm trying to embed simple PHP in HTML.
    >>>>> as follows:
    >>>>>
    >>>>> <html>
    >>>>> <head>
    >>>>> <title>PHP Test</title>
    >>>>> </head>
    >>>>> <body>
    >>>>> <html>
    >>>>> <head></head>
    >>>>> <body class="page_bg">
    >>>>> <?php echo<p>Hello World</p>
    >>>>
    >>>> Terminate php encapsulation with "?>"
    >>>>
    >>>>> Today is:<? print(Date("l, F jS, Y")); ?>.
    >>>>
    >>>> use "date" not "Date"
    >>>> encapsulate php with "<?php ?>" and not"<? ?>"
    >>>>
    >>>>> </body>
    >>>>> </html>
    >>>>
    >>>>> --- This doesn't work either--
    >>>>>
    >>>>> <?php
    >>>>> $today = date("F j, Y");
    >>>>> PRINT "$today";
    >>>>
    >>>> try "print" and not "PRINT"
    >>>>
    >>>>> ?>
    >>>>>
    >>>>> The 'Hello World' and 'Today is:' display as expected, but the date
    >>>>> part
    >>>>> does not display.
    >>>>> I have tried Echo in place of print, same problem. All examples I've
    >>>>> found
    >>>>> are using the same syntax.
    >>>>
    >>>> try "echo" and not "Echo"
    >>>>
    >>>>> What am I missing?
    >>>>> Any suggestions appreciated.
    >>>>
    >>>> Try this exactly as I have typed it:
    >>>>
    >>>> <?php echo date(DATE_RFC2822); ?>
    >>>>
    >>>> if that works, try this, again exactly as I have typed it:
    >>>>
    >>>> <?php echo date("F j, Y"); ?>
    >>>>
    >>>> Apologies if you didn't actually type things the way you said you did,
    >>>> but I'm assuming that you've taken care to accurately report the
    >>>> commands that aren't working including capitalisation.
    >>>>
    >>>> Rgds
    >>>>
    >>>> Denis McMahon
    >>>>
    >>> This does not work:
    >>> <?php echo date(DATE_RFC2822); ?>
    >>>
    >>> Here is the test file live http://www.hepptech.com/phptest.htm
    >>>
    >>>

    >>
    >> Just what I thought, rename your file phptest.php and see if it works.
    >> Also fix your quotes as I showed you in another post.
    >>
    >> --
    >> Take care,
    >>
    >> Jonathan
    >> -------------------
    >> LITTLE WORKS STUDIO
    >> http://www.LittleWorksStudio.com
    >>

    >
    > Jonathan
    >
    > I had the phptest.php file all along, but I was trying to get the php code
    > to work embeded in a .HTM page.
    > So, must I use a .PHP page suffix for any page containg php?
    >
    > I was under the impression that I could use php in a .HTM page as suggested
    > here http://www.ntchosting.com/php/php-in-html.html
    >
    > I'll be reviewing the replies to this post again to be sure I understand.


    In your htaccess add this.
    AddType application/x-httpd-php .html

    --
    idle
    Die IE6
    http://mrdoob.com/lab/javascript/effects/ie6/
     
    idle, Dec 24, 2010
    #12
  13. On 24/12/10 20:47, James wrote:

    > I was under the impression that I could use php in a .HTM page as suggested
    > here http://www.ntchosting.com/php/php-in-html.html


    That depends on the configuration of the webserver.

    The same applies to short tags.

    I suspect that the OP would be well advised to (1) NOT use short tags
    and (2) Name the files .php

    Rgds

    Denis McMahon
     
    Denis McMahon, Dec 24, 2010
    #13
  14. idle wrote:
    > On Fri, 24 Dec 2010 14:47:13 -0600, James wrote in alt.html:


    >>
    >> I was under the impression that I could use php in a .HTM page as suggested
    >> here http://www.ntchosting.com/php/php-in-html.html
    >>
    >> I'll be reviewing the replies to this post again to be sure I understand.

    >
    > In your htaccess add this.
    > AddType application/x-httpd-php .html
    >



    Generally that is no a good idea to force the server to parse even
    static html documents as PHP. If you only have a few files you could use
    force type in your .htaccess file

    # make server foo.html as a PHP script
    <Files foo.html>
    ForceType application/x-httpd-php
    </Files>



    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Dec 24, 2010
    #14
  15. James

    William Gill Guest

    On 12/24/2010 3:09 PM, James wrote:
    > I'll have to understand the parsing matter better.
    >

    Why don't you want to use the .php suffix?

    Your server can be told to parse .htm as .php, but as Jonathan pointed
    out, that's not a good idea. Why burden the server with parsing every
    static html document as if it were PHP, looking for PHP commands that
    aren't there most of the time?

    If your aversion to using the .php suffix is insurmountable a ForceType
    or SetHandler directive can be used to add the unnecessary performance
    hit to the server.
     
    William Gill, Dec 25, 2010
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wenjie

    if (f() != FAIL) or if (FAIL != f())?

    Wenjie, Jul 28, 2003, in forum: C Programming
    Replies:
    3
    Views:
    482
    E. Robert Tisdale
    Jul 31, 2003
  2. globalrev
    Replies:
    32
    Views:
    1,131
    Tobiah
    Oct 6, 2008
  3. Rajive Narain
    Replies:
    0
    Views:
    2,091
    Rajive Narain
    Sep 18, 2009
  4. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    765
    Skybuck Flying
    Oct 4, 2009
  5. __
    Replies:
    1
    Views:
    132
    Gregor Kofler
    Oct 2, 2007
Loading...

Share This Page