Skip to content Skip to sidebar Skip to footer

How To Implement Php In Html File

so I'm basically brand new to web based stuff. My university has given me a cPanel hosted server. I need to implement some basic php functions for my main web page. This is what my

Solution 1:

Your file name needs to be .php. If the web server is set up with PHP (which I'm going to assume it is) then it will handle the php file fine.

Rename the index.html for now and by default the index.php will be the first page to load.

Solution 2:

The file you are using is index.html. This means that it can only display static text and that's the reason why your PHP code is not working.

All you have to do is change the extension from .html to .php then your PHP code should work.

Although I would suggest you Google a few Intro. to HTML and PHP tutorials to get you going on the basics

Solution 3:

The file's extension needs to be changed from *.html to *.php or the PHP won't execute, it'll just be treated like raw HTML.

Here's a quick very basic step-by-step of what's happening:

  1. The client requests index.php

  2. Your web server recognizes the *.php extension and tells PHP to interpret it

  3. PHP parses the text looking for PHP code, and evaluates that code, then replaces the PHP code with the output of that PHP code (if any)

    For example:

    $strVar = 'world';
    echo'<span class="contentText">hello ' . $strVar . '</span><br />';
    

    is replaced with that code's output:

    <span class="contentText">hello world</span><br />
    
  4. The resulting HTML is then returned to the client as content to be rendered by the client's web browser

  5. The client's web browser parses the HTML and renders a web page

Post a Comment for "How To Implement Php In Html File"