Change document from HTML to PHP

1

People, how do I turn an HTML file into PHP? Just change the extension? Is it okay to do so? Apparently, my server read the page I changed from HTML to PHP, but I have doubts whether it's right or not, after all, I've just changed the extension from .html to .php .

    
asked by anonymous 24.08.2017 / 19:58

5 answers

3

Mikaela, imagine that you have a file named index.html with the content described below:

<!DOCTYPE html>
<html>
    <head>
        <title>Aprendendo HTML e PHP</title>
    </head>

    <body>

        <p>Prazer, me chamo Godfrey the King.</p>

    </body>
</html>

You, as a curious person, decided to change the extension to .php .

When you open the page in your browser - remembering that you need to have a web server installed on your computer, which is easily installed using XAMPP, WAMP, EasyPHP, among others. - the following will appear: phrase:

"Prazer, me chamo Godfrey the King."

If you change the code a bit, to:

<!DOCTYPE html>
<html>
    <head>
        <title>Aprendendo HTML e PHP</title>
    </head>

    <body>

        <?php $nome = "Mikaela"; ?>

        <p>Prazer, me chamo <?php echo $nome; ?>.</p>

    </body>
</html>

The phrase will be replaced by: "Prazer, me chamo Mikaela.".

Now do a little test and change the file extension to .html again and reload the page.

Did you notice the difference?

  

HTML is a markup language used in the construction of pages in the   Web. HTML documents can be interpreted by browsers .

     

PHP is a free interpreted language, originally used only   for the development of present and active applications on the   server. PHP scripts are interpreted on the server side .

    
24.08.2017 / 21:20
0

Just do this, changing to php you make your server understand that that page have codes in php. If you try to, for example, run a php code with a * .html file, nothing will happen, it will only print a text on the screen with your code.

    
24.08.2017 / 20:08
0

Changing the extension will only present a problem if the page needs to execute some instruction in PHP .

Example code page that will not have problem in both extensions:

<h1>Hello World!</h1>

The "Hello World!" below will only be displayed if you have the extension in PHP :

<h1><?php echo 'Hello World!'; ?></h1>
  

For the code PHP to run it must be on a Web server   prepared, like Apache for example.

    
24.08.2017 / 20:12
0

To change is just to change the file extension, do not forget to put the .php file on an Apache server (you can use xampp, wampp ... for testing)

    
24.08.2017 / 20:22
0

First you need to understand what is front-end and back-end, these questions should help:

So that's how it works, your machine / browser requests via HTTP a page on your site, PHP does not run on your machine, it's a script that generates an HTTP response and sends via download to its corresponding machine the request, something like these illustrations:

and

In other words, PHP processes a response that is HTML and depending on the server configuration the .php extension will not even exist, this is just a way the language uses to facilitate page creation.

The HTTP responses generated by your PHPs can be anything like: json, image, html, txt, etc.

    
24.08.2017 / 21:37