Help: PHP works with .php but not .html 
Author Message
 Help: PHP works with .php but not .html

How do I get PHP commands embedded in an HTML file to be parsed?

I have been hired to move a current web site written with HTML and PHP to
a hosted server.  All of the files have the .html extension.  But when the
pages are viewed the PHP code is showing up in the page and all of the PHP
code is viewable with the View Source command.

I experience this on both my MacOS X/Apache 2/PHP 4.2.1 and the
Intel/Apache ?/PHP ? hosting server.

When I change the extension to .php, the pages perform better.  I have
changed the tags between <? echo ?>, <script language="php"> echo
</script>, <script TYPE="text/php" language="php"> echo </script>, and
<?php echo ?>.  Doesn't make a difference.

Examples:
TAGS.HTML

<HTML>

<?php echo("if you want to serve XHTML or XML documents, do like this\n"); ?>

  <? echo ("this is the simplest, an SGML processing instruction\n"); ?>
    <?= expression ?> This is a shortcut for "<? echo expression ?>"

  <script language="php">
        echo ("some editors (like FrontPage) don't
              like processing instructions");
    </script>

  <% echo ("You may optionally use ASP-style tags"); %>
    <%= $variable; # This is a shortcut for "<% echo . . ." %>

</HTML>

Output:
This is a shortcut for ""

TAGS.PHP
code same as above

Output:
if you want to serve XHTML or XML documents, do like this this is the
simplest, an SGML processing instruction expression This is a shortcut for
"expression" some editors (like FrontPage) don't like processing
instructions



Sat, 09 Apr 2005 12:46:04 GMT  
 Help: PHP works with .php but not .html

Quote:

> How do I get PHP commands embedded in an HTML file to be parsed?

The same was as you do with .php pages (described in both the Apache and PHP
docs). You probably don't want to do this, though - ALL of your pages would
go through PHP, meaning a potentially horrible performance hit.

Quote:
> When I change the extension to .php, the pages perform better.  I have
> changed the tags between <? echo ?>, <script language="php"> echo
> </script>, <script TYPE="text/php" language="php"> echo </script>, and
> <?php echo ?>.  Doesn't make a difference.

Because html is not a server-parsed format, by default, and PHP is - so
anything in those tags (in an HTML) file) is going to go straight to the
user, as-is.

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.



Sat, 09 Apr 2005 14:37:47 GMT  
 Help: PHP works with .php but not .html
There is an entry in the Apache config file which identifies which files are
to be handed to PHP to process. Look for:

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

If you want .html files to be processed by PHP then you must add this to the
list.

Generally though I would advise against it. If your site contains files
which are pure HTML then it is a waste of time passing them through PHP
before they are displayed. If a file contains any PHP commands then it
should have a .php extension so that it is automatically routed through PHP.

I think the lines referring to <script language="php"> are totally wrong as
they are for identifying client-side scripting, and PHP is server side only.
Stick to "<?php" and "?>" just like it says in the manual.


Quote:
> How do I get PHP commands embedded in an HTML file to be parsed?

> I have been hired to move a current web site written with HTML and PHP to
> a hosted server.  All of the files have the .html extension.  But when the
> pages are viewed the PHP code is showing up in the page and all of the PHP
> code is viewable with the View Source command.

> I experience this on both my MacOS X/Apache 2/PHP 4.2.1 and the
> Intel/Apache ?/PHP ? hosting server.

> When I change the extension to .php, the pages perform better.  I have
> changed the tags between <? echo ?>, <script language="php"> echo
> </script>, <script TYPE="text/php" language="php"> echo </script>, and
> <?php echo ?>.  Doesn't make a difference.

> Examples:
> TAGS.HTML

> <HTML>

> <?php echo("if you want to serve XHTML or XML documents, do like this\n");
?>

>   <? echo ("this is the simplest, an SGML processing instruction\n"); ?>
>     <?= expression ?> This is a shortcut for "<? echo expression ?>"

>   <script language="php">
>         echo ("some editors (like FrontPage) don't
>               like processing instructions");
>     </script>

>   <% echo ("You may optionally use ASP-style tags"); %>
>     <%= $variable; # This is a shortcut for "<% echo . . ." %>

> </HTML>

> Output:
> This is a shortcut for ""

> TAGS.PHP
> code same as above

> Output:
> if you want to serve XHTML or XML documents, do like this this is the
> simplest, an SGML processing instruction expression This is a shortcut for
> "expression" some editors (like FrontPage) don't like processing
> instructions



Sat, 09 Apr 2005 14:46:48 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. http authentication with php not working - need help

2. Apache + PHP not processing php

3. UTF8 php files are not interpreted by PHP ! :-(

4. php is not interpreted (apache 2.0.43, php 4.3.0, linux)

5. Variable not passing in HTML form to PHP sendmail script

6. mysql is not working with php

7. PHP Java works with http:// but not https://

8. Simple PHP beginner script not working!

9. Why is my PHP server not working correctly ?

10. File Upload (html + php code) help please.

11. HELP : Cannot get PHP to work on win98 machine

12. php newsgroup [ alt.php ]

 

 
Powered by phpBB® Forum Software