Need help on PHP / HTML

Discussion in 'PHP' started by merlinseo, Jun 29, 2009.

  1. #1
    Hi,
    Dear all i am not too good in PHP but have one query to get solved, Please help

    Is it possible to have a HTML index page named index.html and call PHP functions in that HTML coded page

    For example : I keep my home page as index.html and now can i call a php code in that HTML code to display something.

    Like my page is pure HTML and i want to display the blog post on the HTML index page below my HTML design

    Is there way that I design a HTML page with nice looks and then in that page some where in corner I call PHP function to display my blog posts only by calling PHP function

    Please help
     
    merlinseo, Jun 29, 2009 IP
  2. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #2
    You cannot put PHP in HTML pages. The PHP interpreter will not parse it and it will come out as plain text. Instead, save your file as index.php - then you can place PHP in the HTML as follows:

    
    <html>
    <head>
    <title>PHP in HTML</title>
    </head>
    
    <body>
    Today's date is <? print date("m d, Y"); ?>
    </body>
    </html>
    
    Code (markup):
     
    Louis11, Jun 29, 2009 IP
  3. merlinseo

    merlinseo Well-Known Member

    Messages:
    1,686
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Ok understood but my requirement is that i need the files as index.html
    Because i have a website which is already up and running and it has all the files as .html and now i want to add blog on home page only where i can have some posts via blog. The reason is , I have PR3 for index.html file or domain

    So if i change it to .php, will it affect my PR ???
     
    merlinseo, Jun 30, 2009 IP
  4. clarky_y2k3

    clarky_y2k3 Well-Known Member

    Messages:
    114
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Incorrect.

    Providing your server is using Apache (which it likely is) then you can place the following in your .htaccess file:-
    
    AddType application/x-httpd-php .html
    
    Code (markup):
     
    clarky_y2k3, Jun 30, 2009 IP
  5. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #5
    By default, PHP doesn't look in HTML files to parse PHP. Your method is technically correct, but generally speaking PHP does not parse HTML - therefore i'm not incorrect ;) You could also rewrite your URLs if you really wanted to to mask the .php extension. Though Clarky's solution works well also.
     
    Louis11, Jun 30, 2009 IP
  6. freemori

    freemori Peon

    Messages:
    54
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Open apache's httpd.conf file,find "DirectoryIndex" and make index.php befor index.html .
    such as :"DirectoryIndex index.php index.php3 index.html index.htm"
    then you can access the index.php file by your domain ,no need include index.php
     
    freemori, Jul 1, 2009 IP