inline php not working (SOLVED)

Alles, was PHP betrifft, kann hier besprochen werden.

inline php not working (SOLVED)

Postby edpatterson » 10. June 2011 14:26

Sorry, I really did use Google. Found lots of instances of the issue, no definitive answers.
XAMPP 1.7.2 Windows

I created this test file inlinephp.html
Code: Select all
<html><head><title>Inline PHP testing</title></head>
<body>
<?php echo "<h1>This header was done in php</h1>\n"; ?>
This line was done in html
</body>
</html>

It displayed
Code: Select all
This header was done in php\n"; ?> This line was done in html

PHP is working fine, all files with a .php extension work perfectly, I would like to be able to use some simple php code in .html files.

Is this possible.

Thanks,
Ed
edpatterson
 
Posts: 4
Joined: 08. October 2010 15:04

Re: inline php not working

Postby edpatterson » 10. June 2011 15:47

new code
Code: Select all
<html><head><title>Inline PHP testing</title></head>
<body>
<?php
echo "<h1>This header was done in php</h1><br>";
?>
This line was done in html
</body>
</html>

Produces
Code: Select all
This header was done in php
"; ?> This line was done in html
edpatterson
 
Posts: 4
Joined: 08. October 2010 15:04

Re: inline php not working

Postby Altrea » 10. June 2011 19:52

just save the file with a .php extension and request it with the http protocol in your browser.
Apache is by default not configurated to parse php code in .html files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
free software according to purpose of usage
XAMPP 1.8 for local development/testing only
Zend Server 6 (free) for production environments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 4637
Joined: 17. August 2009 13:05
XAMPP Version: 1.8.1
Operating System: W7Ux64

Re: inline php not working

Postby edpatterson » 10. June 2011 23:16

Thanks, I was hoping to find out how to configure php/apache so that inline code would work with the .html extension.

Ed
edpatterson
 
Posts: 4
Joined: 08. October 2010 15:04

Re: inline php not working

Postby Altrea » 11. June 2011 09:37

Thats possible, but why should anybody do this?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
free software according to purpose of usage
XAMPP 1.8 for local development/testing only
Zend Server 6 (free) for production environments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 4637
Joined: 17. August 2009 13:05
XAMPP Version: 1.8.1
Operating System: W7Ux64

Re: inline php not working

Postby edpatterson » 11. June 2011 22:09

I am trying to trouble shoot dynamically creating html forms via PHP and MySQL.
edpatterson
 
Posts: 4
Joined: 08. October 2010 15:04

Re: inline php not working

Postby Altrea » 11. June 2011 23:09

I don't see why therefor it is needed to parse .html files with the php parser.
But it's your server, so it's up to you.

- open your file \xampp\apache\conf\extra\http-xampp.conf
- line 22 (or somewhere around that) should be
Code: Select all
<FilesMatch "\.php$">


- change it to
Code: Select all
<FilesMatch "\.(php|html)$">


- restart your Apache.
Now all .html files take their way through the php parser.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
free software according to purpose of usage
XAMPP 1.8 for local development/testing only
Zend Server 6 (free) for production environments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 4637
Joined: 17. August 2009 13:05
XAMPP Version: 1.8.1
Operating System: W7Ux64

Re: inline php not working

Postby Altrea » 02. October 2011 16:30

The solution is posted in this post.
If that doesn't work for you, please open an own topic with a qualified error description.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
free software according to purpose of usage
XAMPP 1.8 for local development/testing only
Zend Server 6 (free) for production environments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 4637
Joined: 17. August 2009 13:05
XAMPP Version: 1.8.1
Operating System: W7Ux64


Return to PHP

Who is online

Users browsing this forum: No registered users and 3 guests