PDA

Click to See Complete Forum and Search --> : PHP code in .html file


VBSpike
Nov 6th, 2001, 07:14 AM
Is there a way to add a php code inside the html file (and save that file with .html extension rather than .php). My boss doesn't want .php files (which is what I have now) so he asked me to find a way to change it to .html. But honestly I don't even know how to do it.
I'm looking for something like this:

<html>
<head>
<title>STUPID TITLE</title>
</head>
<body>
SOME TEXT IMAGES, TABLES GO HERE
and then I want to add php formatted table with some data from the text file
<?php MYPHPCODEHERE ?>
</body>
</html>
I tried the above but don't seem to make it work (I'm getting the code itself displayed rather than the table that should appear)

Thanks

Spike

Cander
Nov 6th, 2001, 09:40 AM
No. He is just going top have to live with php files

JoshT
Nov 6th, 2001, 10:48 AM
You should be able to configure your server to have .html files be processed by PHP. See your web server docs, or maybe the php manual. Doing so will slow your server down, though, because it will attempt to process any static html files as well.

What's your boss's reasoning? Using .php for php is a perfectly normal thing to do.

scoutt
Nov 6th, 2001, 12:42 PM
well you have 2 choices, actually 3, but the 1st one is you can have php code in there and name the file a .phtml ( some servers have problems with this configuration) regualr.html files won't process php. has to be either .php or .phtml or php3.

or you can use this.
<script language="php" runat="server">

you code here
(not sure if you need the <? ?> tags)
</script>

or take the php out and do it normally. I would also have to agree with josh, what's your bosses reasoning?

VBSpike
Nov 6th, 2001, 12:46 PM
you'd have to know my boss to understand :D

Thanks for your help

Spike

JoshT
Nov 6th, 2001, 12:58 PM
regualr.html files won't process php. has to be either .php or .phtml or php3.

No, this is arbitrary. You can configure the server to process any file extension you want as php (or anything else). You could map *.php files to Perl and *.asp files to PHP if you wanted.

scoutt
Nov 6th, 2001, 01:03 PM
Originally posted by JoshT


No, this is arbitrary. You can configure the server to process any file extension you want as php (or anything else). You could map *.php files to Perl and *.asp files to PHP if you wanted.
I see your point, but

in the meantime when you set the server up to parse anything as php (if it was an isp) then it would mess everyone else up. Unless they own there own server it might be an idea, but if it is a shared server it wouldn't work too well.

I would stick with .php or .phtml becasue it is easier.

JoshT
Nov 6th, 2001, 01:47 PM
I was assuming Spike has their own server (?)

I agree with sticking to .php - otherwise you could end up with maintenance troubles.

sail3005
Nov 6th, 2001, 03:41 PM
Originally posted by scoutt
well you have 2 choices, actually 3, but the 1st one is you can have php code in there and name the file a .phtml ( some servers have problems with this configuration) regualr.html files won't process php. has to be either .php or .phtml or php3.

or you can use this.
<script language="php" runat="server">

you code here
(not sure if you need the <? ?> tags)
</script>

or take the php out and do it normally. I would also have to agree with josh, what's your bosses reasoning?

cool, so will that work without special server configuration?

scoutt
Nov 6th, 2001, 08:55 PM
not sure, I never tried it I was jsut told it works. everytime I want to try it I end up getting busy with something else then forget about it. try it out and see... :)

scoutt
Nov 7th, 2001, 08:04 AM
forgot to add runat="server" part. did you try it without the <? ?>

da_silvy
Nov 7th, 2001, 02:05 PM
yep

sail3005
Nov 7th, 2001, 03:20 PM
:( you should be able to config it to work. it works with ASP.

scoutt
Nov 7th, 2001, 07:22 PM
Sail, you tried that script as ASP in an html document and it worked? cool... :cool:

The Hobo
Nov 7th, 2001, 08:25 PM
Originally posted by VBSpike
Is there a way to add a php code inside the html file (and save that file with .html extension rather than .php). My boss doesn't want .php files (which is what I have now) so he asked me to find a way to change it to .html. But honestly I don't even know how to do it.
I'm looking for something like this:

<html>
<head>
<title>STUPID TITLE</title>
</head>
<body>
SOME TEXT IMAGES, TABLES GO HERE
and then I want to add php formatted table with some data from the text file
<?php MYPHPCODEHERE ?>
</body>
</html>
I tried the above but don't seem to make it work (I'm getting the code itself displayed rather than the table that should appear)

Thanks

Spike

If he can deal with .shtml files, you can probably do what you want with php in cgi and call it in the file?

scoutt
Nov 7th, 2001, 08:53 PM
curious on how you would accomplish that?

da_silvy
Nov 8th, 2001, 12:45 AM
you can use
#!/usr/bin/php

at the start of a cgi file, and it is parsed, slower, but like a php file ;)

scoutt
Nov 8th, 2001, 08:01 AM
my ISP requires that line in all my files, ( well the main ones actually) so you still have to have the php extension and not .html

da_silvy
Nov 8th, 2001, 02:46 PM
freedom 2 surf needs them also...

JoshT
Nov 8th, 2001, 03:23 PM
They should modernize to mod_php instead of cgi then...:(

da_silvy
Nov 9th, 2001, 01:25 AM
heheheh

:rolleyes:

They should, besides, they're too slow