Results 1 to 21 of 21

Thread: PHP code in .html file

  1. #1
    VBSpike
    Guest

    PHP code in .html file

    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

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    No. He is just going top have to live with php files
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  4. #4
    scoutt
    Guest
    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?

  5. #5
    VBSpike
    Guest
    you'd have to know my boss to understand

    Thanks for your help

    Spike

  6. #6
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    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.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  7. #7
    scoutt
    Guest
    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.

  8. #8
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I was assuming Spike has their own server (?)

    I agree with sticking to .php - otherwise you could end up with maintenance troubles.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  9. #9
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    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?

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  10. #10
    scoutt
    Guest
    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...

  11. #11
    scoutt
    Guest
    forgot to add runat="server" part. did you try it without the <? ?>

  12. #12
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    yep

  13. #13
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    you should be able to config it to work. it works with ASP.

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  14. #14
    scoutt
    Guest
    Sail, you tried that script as ASP in an html document and it worked? cool...

  15. #15
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: PHP code in .html file

    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?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  16. #16
    scoutt
    Guest
    curious on how you would accomplish that?

  17. #17
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    you can use
    #!/usr/bin/php

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

  18. #18
    scoutt
    Guest
    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

  19. #19
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    freedom 2 surf needs them also...

  20. #20
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    They should modernize to mod_php instead of cgi then...
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  21. #21
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    heheheh



    They should, besides, they're too slow

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width