SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    include html file in php

    Hi,

    I want to include html file in php.Could anyone let me know how to do that.

    The pb is I have php code in html file.As I changed my httpd.conf file to recognise html files,my html file is working fine on my computer.But when uploaded to my website,it is not recognising php code in html file.And my web host is not willing to do that.So I am planning to include all my html code in one file and inserting include html in php file.

    Pls help me on this.

    Thanks

  2. #2
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Kansas City, MO
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?PHP include("htmlfile.html");?>

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    What should I do if I want include php file in html?

  4. #4
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Kansas City, MO
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean you want to use PHP markups in the HTML or call a PHP file from the HTML file?

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    actually I have php embedded in html file,but the pb is I don't have access to httpd.conf file of apache.So,it is not recognising php code in html file.I have to comeout of this problem
    Pls help
    Thanks

  6. #6
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    California
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML and PHP can be integrated into one php file.

    PHP Code:
    <?php
     
    echo '<html><head><title>test</title></head><body>test</body></html>'?>
    This also works:

    PHP Code:
    <?php
       
    // optional code here
       
    ?>
       <html>
       <head>
       <title>test</title>
       </head>
       <body>
       test
       <?php
       
    // back to php
       // some code
       
    ?>
       <?php /* we can include php in one line if we want */ ?>
       </body>
       </html>
       <?php
       
    // done
       
    ?>

  7. #7
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change the extension of the .html file to .php

  8. #8
    Non-Member Dan's Avatar
    Join Date
    Feb 2005
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What should I do if I want include php file in html?
    You can't

  9. #9
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by krustie
    You can't
    .htaccess
    Code:
    AddType application/x-httpd-php .html
    hello.html
    PHP Code:
    <html>
    <head>
    </head>
    <body>
    <?php echo 'Hello, World!'?>
    </body>
    </html>

  10. #10
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by scottatmu
    <?PHP include("htmlfile.html");?>
    Actually, you should use readfile instead of include, as include will parse it as if it is PHP. Apart from being a performance hit, it could be a security risk if you are not sure whether somebody has put PHP in that HTML file.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  11. #11
    SitePoint Evangelist
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The creater of the thread isn't making much sense, but I think they want a PHP code inside a .html file.

    Therefore,
    PHP Code:
    <script language="PHP">blahblaj</script> 
    Might work, I wish you luck

  12. #12
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, that won't work. The question has already been answered, add this to your .htaccess file:

    Code:
    AddType application/x-httpd-php .html
    Mike
    It's not who I am underneath, but what I do that defines me.

  13. #13
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Could anyone look into this and let me know where I am not able to figure it out error.
    It is giving parse error on line 14.

    <?php

    echo '<html> <head> <title></title>';

    echo '</head>';

    echo '<body bgcolor="#FFFFFF">';


    echo '<h1>Update Contact</h1>';

    echo '<font face=arial color=red size=2></font>';

    echo '<form name=form1 method=post action='contactform.php' onsubmit='return Validate_Form()'>';

    echo '<table width='100%' cellspacing=2 cellpadding=2>';

    echo '<tr> <td valign='top' align='right'>Emails/td> <td valign='top' align='left'>';

    echo '<input type=text name=newemail size=25 value=$email1> ';

    echo '<font size=1>(Separate emails by ,)</font></td>';
    echo '</tr>';
    echo '<tr> <td valign='top' align='right'>&nbsp;</td> <td valign='top' align='left'>&nbsp;</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td valign='top' align='right'>Contact Text/td>';

    echo '<td valign='top' align='left'><textarea name="text" cols="50" rows="9">';

    echo "$message1";
    echo '</textarea></td>';
    echo '</tr>';
    echo '<tr> <td valign='top' align='right'>&nbsp;</td>';

    echo '<td valign='top' align='left'><input name="submit" type=submit value='Save' >';
    echo '</td>';

    echo '</tr>';
    echo '</table>';
    echo '</form>';

    echo '</body>';
    echo '</html>';

    ?>

    Pls help.I am not able to see where the error is.

    Thanks

  14. #14
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo '<form name=\'form1\' method=\'post\' action=\'contactform.php\' onsubmit=\'return Validate_Form()\'>'
    There.

  15. #15
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

  16. #16
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're going to have a lot of parse errors.

    What you're going to have to do is escape all the single quotes with backslashes if you want to you use them in a single quoted string.

  17. #17
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    <?php 

    echo<<<EOF
    <html>
    <head>
    <title></title>
    </head>
    <body bgcolor="#FFFFFF">
    <h1>Update Contact</h1>
    <form name='form1' method='post' action='contactform.php' onsubmit='return Validate_Form()'>
    <table width='100%' cellspacing='2' cellpadding='2'>
    <tr>
    <td valign='top' align='right'>Emails:</td>
    <td valign='top' align='left'>
    <input type='text' name='newemail' size='25' value='
    {$email1}' /> 
    <font size='1'>(Separate emails by ,)</font>
    </td>
    </tr>
    <tr>
    <td valign='top' align='right'>&nbsp;</td>
    <td valign='top' align='left'>&nbsp;</td>
    </tr>
    <tr>
    <td valign='top' align='right'>Contact Text:</td>
    <td valign='top' align='left'>
    <textarea name="text" cols="50" rows="9">
    {$message1}
    </textarea>
    </td>
    </tr>
    <tr>
    <td valign='top' align='right'>&nbsp;</td>
    <td valign="top" align='left'><input name="submit" type="submit" value="Save" />
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    EOF;
    ?>
    Mike
    It's not who I am underneath, but what I do that defines me.


Bookmarks

Posting Permissions

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