In my HTML-page I am using following HTML + PHP-code:

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

I would expect to see:
Today is: monday October 4, 2010.
or something like that.

The only thing I see is:
Today is:.
(mind the dot at the end.

This means the PHP-code is not processed!

PHP-code in a .php file works fine.
Adding 'AddType application/x-httpd-php .htm .html' to the .htaccess file = no success
Adding 'addtype application/x-httpd-php .php .htm .inc .html' to the .htaccess file = no success either.

Is there something wrong with my hosting-provider? (on Apache server)
Or am I making some mistake?

Please help, as I am puzzling for many days now.

First, make sure that the file is saved with a .php extension. Then try this:

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

It could be that the uppercase "D"ate is causing the issue. Also, you are using short tags <? ?>. Some server configurations do not allow this. Instead, always use the full tags <?php ?>

Hi, I checked this:

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

and everything worked fine. you may want to use <?php and not just <?

Just add the php to the start line. See below

<?php print(Date("l F d, Y")); 
?>

I tested the code and got the following result:

Hope this helps

Max

Monday October 04, 2010

Thank you all for your reply, but ...

1) I do NOT want to put this piece of code into a PHP-file, as I want to use php INSIDE html to mask a hard-written e-mail address to prevent spam-robots finding it. (other solutions for that are welcome also)

2) All options given are already tested and not-working on the Apache-server of MY hosting-provider.
It IS working on anoter Apache-server at another hosting-provider!

So it must be something malfunctioning on the Apache-server at my hosting-provider.
I hope someone has knowledge of that kind of settings.

1) I do NOT want to put this piece of code into a PHP-file, as I want to use php INSIDE html to mask a hard-written e-mail address to prevent spam-robots finding it. (other solutions for that are welcome also)

All PHP code must be saved within a file with a .php extension otherwise it will not be interpreted! Regardless of where it is located (e.g. nested in html). You could encrypt the email address that is hard coded, or grab the email address dynamically. There are plenty of options for this!


2) All options given are already tested and not-working on the Apache-server of MY hosting-provider.
It IS working on anoter Apache-server at another hosting-provider!
So it must be something malfunctioning on the Apache-server at my hosting-provider.
I hope someone has knowledge of that kind of settings.

If you send us some more examples of the code that is/isn't working, we can try and give you more specific help!

You don't have to have the whole page written in PHP if it's saved as a .php file. You could have the whole page written in HTML if you wanted. Either way, the end user will never see the PHP code even if they try to view it as the browser will process the code and output the resulting HTML to the source file that they will see if they choose to "view source code".

Hi,

It is NOT so that PHP-code always must be stored into a .php-file.
The code (stored as .htm-file) below IS Working (!) on one of my providers Apache server.
The same code is NOT working on another provider's Apache server!

So there most be something wrong with the setting of the second provider.
But they (Starthosting.nl) refuse any help.
The only thing I can do is add some option(s) in the .htaccess-file to overrule default settings.
Only ... which one?
I already added: AddType application/x-httpd-php .htm .html

Maybe you can try it yourself with following code (Change the variables $lx01 to $lx04 to make a proper e-mail address.):

<html>

<head>
<meta http-equiv="Content-Language" content="nl">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>New Page 1</title>

</head>

<body>

<p>This is a <font color="#0000FF"><b>Zero Test</b> </font>page for testing PHP code.</p>
<p>There aren <font color="#FF0000">no links</font> to other pages or PHP-files.</p>

<p><b>Test-code</b>:</p>
<p>&nbsp;</p>
PHP without &lt;p /p&gt; :&nbsp;&nbsp;
Hello, today is <?php echo date("l, F jS, Y"); ?>.
<p>PHP with &lt;p /p&gt;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hello, today 
is &lt;?php echo date("l, F jS, Y"); ?&gt;.</p>
You can send an e-mail to: <?php
$lx01 = "yourname";
$lx02 = "nl";
$lx03 = "gmail";
$lx04 = "com";
$tx = $lx01 . "."  .$lx02 . "@" . $lx03 . "." . $lx04;
echo "<b>$tx</b>";
?>
</body>

</html>

I still hope someone can tell me what .htaccess code to use to make it work.
Thank you in advance

In my HTML-page I am using following HTML + PHP-code:

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

I would expect to see:
Today is: monday October 4, 2010.
or something like that.

The only thing I see is:
Today is:.
(mind the dot at the end.

Do this..

In my HTML-page I am using following HTML + PHP-code:

Today is: <?=Date("l F d, Y")?>  // This should work like a charm.

Today is: <?=Date("l F d, Y")?> is just a short notation for
Today is: <?php=Date("l F d, Y")?>

None is working on Starthosting.nl, so it must be some setting in the php.ini-file owned by the hosting-provider. They don't want to change anything in that file (I think they don't know what to do.)
So the only thing I can do is overrule some php-setting(s) using the .htaccess file.

But WHAT should I overrule? And how?

Today is: <?=Date("l F d, Y")?> is just a short notation for
Today is: <?php=Date("l F d, Y")?>

no, there is a bug in the second.
<?php=Date("l F d, Y")?> // no good man.
syntax is wrong.
its either

<?php echo Date("l F d, Y"); ?> 

//or
 <?=Date("l F d, Y")?> .

and they should work fine in any server. They are both standard php short and normal tag. Not asp tags.

If this does not, then their server is not php enabled.
:)

no, there is a bug in the second.
<?php=Date("l F d, Y")?> // no good man.
syntax is wrong.
its either

<?php echo Date("l F d, Y"); ?> 

//or
 <?=Date("l F d, Y")?> .

and they should work fine in any server. They are both standard php short and normal tag. Not asp tags.

If this does not, then their server is not php enabled.
:)

My mistake in the last reaction (Oct. 6). Sorry.

The real statement I'm using is:
Hello, today is <?php echo date("l, F jS, Y"); ?>.

This one IS working at one provider, not on the 'bad' one's server.
There however PHP is installed and working for seperate .php-files.
Only Inline-PHP is not working.
And they do not want to change their php.ini settings or give any other support :((
I guess they don't know what to change.

So adjusting the .htaccess file is the only option ... if I knew what to adjust.

Look i will give you a free hosting space for a year if you want.

'short_open_tags' = On

in php.ini

and you can use the short tags.

How about that. I've been using Date("l F d, Y",time()); thinking that I had to supply the time.

Learn something new everyday.

What's the point of not saving into PHP and using HTML instead? This will slow down your system a little bit since a pure HTML code should be parsed by PHP.

I'd rather disguise my PHP file as HTML using .htaccess . Visitor will never know what's under the hood after all.

RewriteRule ^(.*)\.html$ /$1.php [L]

that way you can use
http://mysite.com/foo.html
to call
http://mysite.com/foo.php

check your php.ini setting

short_open_tag=1

Step 1: create test.php

<?php
phpinfo();
?>

check short_open_tag=1

if value 0 change to 1 or ask them(hosting-provider) to change it

check your php.ini setting

short_open_tag=1

Step 1: create test.php

<?php
phpinfo();
?>

check short_open_tag=1

if value 0 change to 1 or ask them(hosting-provider) to change it

Thank you for your reply.
The short_open_tag is ON
Any other suggestions/options?

Han

Look speak to your hosting company. They are the best to help you. ;)

Look speak to your hosting company. They are the best to help you. ;)

Voila!

first confirm that you have save the page with '.php' extension.

In case you havent found the answer..

You probably just need to add '.html' to your apache config under the PHP5 module's settings.
Edit your httpd.conf and look for php5_module:

<IfModule php5_module>
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps
        <IfModule dir_module>
                DirectoryIndex index.html index.php
        </IfModule>
</IfModule>

This tells the php5 interpreter module which file types might contain PHP code that it needs to interpret.
You need to tell apache to also expect to find php in '.html' files, so just add .html to the config thusly:

<IfModule php5_module>
        AddType application/x-httpd-php .php .html
        AddType application/x-httpd-php-source .phps
        <IfModule dir_module>
                DirectoryIndex index.html index.php
        </IfModule>
</IfModule>

Save your config and restart apache, then try your html page again. The PHP should now be interpreted correctly.

mikec

goto : C:\xampp\apache\conf\

and add this line to "httpd.conf" :

AddHandler application/x-httpd-php .html

hope this works!

commented: AAAAHHH CRAP, why did that idiot wake up a two years dead thread, waste my bloody time, and give a wrong bloody answer -3

starthosting has disabled add handler server parsed, in php.ini for their convenience
they know exactly what they have done, and yes they refuse to change it..
it is a simple way for them to reduce their server load, NO parsing of html files for php scripts
changes cannot be made in .htaccess, that too is disabled.
BUT: filename changes have not been disabled in php.ini, you can set up displaying .php files as .html extension in .htaccess, so the user will see file.html but the server will parse file.php

just noticed the dates
AAAAHHH CRAP, why did that idiot wake up a two years dead thread and waste my bloody time

mutiple text boxes added thru add button insert these values each rows in mysql database ie each value insert each in table

why does it not work i've tried every tutorial in the internet and it did not work WHY

commented: Notice how old this thread is and the answer at https://www.daniweb.com/posts/jump/2124558 +15

php code in html file not working i'm using xampp on windows10
helpppp plzzzzzzzzzz

commented: It's 9 years ago. Start a new discussion. -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.