+ Reply to Thread
Results 1 to 8 of 8

Thread: Parsing PHP in Html Files

  1. #1
    bnetclanbot54 is offline x10Hosting Member bnetclanbot54 is an unknown quantity at this point
    Join Date
    Jun 2010
    Posts
    2

    Parsing PHP in Html Files

    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 by bnetclanbot54; 06-16-2010 at 03:06 AM.

  2. #2
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Parsing PHP in Html Files

    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 by lemon-tree; 06-16-2010 at 06:12 AM. Reason: Added .htm

  3. #3
    shant93 is offline x10 Sophmore shant93 is an unknown quantity at this point
    Join Date
    Mar 2010
    Location
    Montreal
    Posts
    117

    Re: Parsing PHP in Html Files

    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

  4. #4
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Parsing PHP in Html Files

    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 by lemon-tree; 06-16-2010 at 08:04 AM.

  5. #5
    shant93 is offline x10 Sophmore shant93 is an unknown quantity at this point
    Join Date
    Mar 2010
    Location
    Montreal
    Posts
    117

    Re: Parsing PHP in Html Files

    But wouldn't that still make it difficult to develop locally without a test server?

  6. #6
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Parsing PHP in Html Files

    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 by lemon-tree; 06-16-2010 at 08:07 AM.

  7. #7
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Parsing PHP in Html Files

    There are numerous threads on this topic:
    In any case, running all HTML files through PHP is wasteful. All you need to do is give PHP scripts a "php" extension.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  8. #8
    szhockeykidd is offline x10Hosting Member szhockeykidd is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    20

    Re: Parsing PHP in Html Files

    Quote Originally Posted by misson View Post
    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.
    HTML, xhtml, css, php and asp help available
    PM me if you need help with any.
    Website design and coding help available at http://www.chicken-eggsolutions.com

+ Reply to Thread

Similar Threads

  1. FTP for HTML, etc. Files
    By epotzck in forum Free Hosting
    Replies: 2
    Last Post: 04-19-2010, 12:15 AM
  2. Problems with Apache parsing html as php
    By hezuo in forum Programming Help
    Replies: 6
    Last Post: 01-29-2009, 10:21 AM
  3. Parsing html files for php - .htaccess?
    By onyxmoron in forum Free Hosting
    Replies: 0
    Last Post: 01-06-2009, 03:01 AM
  4. parsing html links with php [100 credits]
    By nahsorhseda in forum Programming Help
    Replies: 5
    Last Post: 06-21-2008, 04:43 AM
  5. Parsing html
    By jensen in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 05-20-2006, 01:21 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers