'Difference between an HTML and a PHP file
I have to query a mysql database using php, but a file with the .html
extension for example my index.html
does not recognize the
<?php ?>
.
Now I have index.php
, what are the differences between this and the index.html
file?
I can work properly with the index.php
file or there is a method to insert <?php //SOME CODE TO MY DB ?>
this type of code into an .html
file?
P.S.
I know that ajax exists, but in all the tutorials I have seen the file extension was .php
and not .html
and I can't understand how to use it.
Solution 1:[1]
They are both text files with code in them.
The difference isn't in the files, but in how your webserver treats them.
It is configured to run files with a .php
extension though a PHP engine, and to serve up .html
files directly.
Solution 2:[2]
You have to open the php file through an apache (or other php-handling) server. For instance, if you use XAMPP, and have index.php in the XAMPP directory, you would open a browser and go to localhost/index.php. The server then converts it into html, which a browser can handle.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Quentin |
Solution 2 | Ythaenagor |