PHP in HTML simple test fail

J

James

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.
 
J

James

Sherm Pendley said:
You're missing a ?> here.

sherm--

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.
 
D

Denis McMahon

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 said:
</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
 
J

James

Denis McMahon said:
Terminate php encapsulation with "?>"


use "date" not "Date"



try "print" and not "PRINT"


try "echo" and not "Echo"


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
 
D

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>
 
J

Jonathan N. Little

James said:
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

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.
 
J

James

Jonathan N. Little said:
should be:

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

or



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.

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.
 
J

Jonathan N. Little

Denis said:
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.
 
J

James

Jonathan N. Little said:
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.

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.
 
I

idle

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
 
J

Jonathan N. Little

idle said:
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>
 
W

William Gill

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top