Parsing PHP in Html Files

bnetclanbot54

New Member
Messages
2
Reaction score
0
Points
0
Hello there I have a problem concerning how to properly parse a PHP File within an .Html file using the
Code:
<?php include("file.php"); ?>
I have googled and searched for this problem for about two days now and I have tried every combination adding and trying every line possible I could find for the .htaccess file.

Does anyknow how to properly execute a phpfile when called upon in an html file? Right now none of my codes are loading in the Div tags i placed them in.
Code:
<div id="apDiv1">
This is a test. </br>
Now here comes the PHP Calls </br>
<?php include("index.php"); ?> 
<?php include("call.php"); ?> 
PHP Calls are now done </br>
</div>
The "This is a test. nNow here comes the PHP Calls, and PHP Calls are now done" do show in the div tag, but the php files dont show at all. No errors or anything it just doesnt show :\
Please, Ive been searching everywhere and looking diligently, yet no avail.
 
Last edited:

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
This'll be done with .htaccess, place this line of code in the .htaccess in the same folder as the html file. This should work, although I can't access the server to test it.
<FilesMatch "\.(html|htm)$">
ForceType application/x-httpd-php5
</FilesMatch>
 
Last edited:

shant93

Member
Messages
119
Reaction score
0
Points
16
I think I might know the problem: the <?php [...] ?> tag can only be used inside a .php file and not a .html/.htm file.

This may cause problems for inexperienced users because .php files cannot be read by browsers, they have to be compiled (is that the right word?) by a server. If you want to work with .php, you have to get a local test server (like WAMPserver or xampp) and view it from /localhost/, or you have to upload using FTP every time you make a change, the latter being very annoying.

Hope this helps,
Shant
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
Normally, you can only use a PHP tag in a .php file unless you specifically tell the server to treat regular html files as PHP script files, which is what the code I posted does.

<FilesMatch "\.(html|htm)$">
Match all files that have the extension .html or .htm

ForceType application/x-httpd-php5
Run the script within the file using the PHP module in Apache.

PHP is never compiled as it is a scripting language, it is merely interpreted.
 
Last edited:

shant93

Member
Messages
119
Reaction score
0
Points
16
But wouldn't that still make it difficult to develop locally without a test server?
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
Yes, if you are writing any PHP code regardless of the file's extension you will need a local copy of Apache that has the PHP module installed.
 
Last edited:

szhockeykidd

New Member
Messages
20
Reaction score
0
Points
0
In any case, running all HTML files through PHP is wasteful. All you need to do is give PHP scripts a "php" extension.
Mission is correct there is no need to run all the files through PHP. Wampserver is a very good server. i also like abyss web server because it is much easier to use with its graphic interface. I was also able to get PHP and asp to work with no problems.
 
Top