Reza Fahmi
Reza Fahmi

Reputation: 262

display php result in html page

how to display php result in html file? this is my index.html file

<html>
<head>
<title>My PHP Page</title>
</head>
<body>
This is HTML code
<?php
include("blabla.php");
?>
Back into HTML
</body>
</html>    

and i want to display the blabla.php result in index.html but the result when i execute the index.html is

This is normal HTML code Back into normal HTML

thanks before :)

Upvotes: 0

Views: 9869

Answers (5)

Chris Edwards
Chris Edwards

Reputation: 1

If the file name already ends with a ".php" extension, it is just a matter of have the php code echo or print the result in a place where you would normally write the code. If it does end with the ".html" extension, just be sure to change the extension to ".php". I have provided a simple example that looks similar to the one you quoted below:

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <p>
          <?php
        echo "Blah, Blah, Blah";
          ?>
        </p>   
    </body>
</html>

Upvotes: 0

Passionate Coder
Passionate Coder

Reputation: 7294

You can't run PHP in .html files because the server does not recognize that as a valid PHP extension unless you tell it to. To do this you need to create a .htaccess file in your root web directory and add this line to it:

AddType application/x-httpd-php .htm .html

This will tell Apache to process files with a .htm or .html file extension as PHP files. for more info please read this http://php.about.com/od/advancedphp/p/html_php.htm

Upvotes: 2

Dan
Dan

Reputation: 183

If you wish to use PHP, your files will have to have the file extension .php.

Are you running your code in a server environment or development environment like XAMPP ? There are guides available like this one to install XAMPP for windows which will help you get started.

Once you have XAMPP setup go to the installation location and then to the folder called htdocs, create a folder and call it test.

Then move both index.php (Rename it from index.html) & blabla.php (again renaming with the .php extension) to the newly created test folder.

Then head over to your web browser and go to localhost/test/index.php and you will hopefully see your webpage as you expect to see it on the screen!

Upvotes: 0

Nay
Nay

Reputation: 27

The main page should be saved with a file extension of .php to properly retrieve and execute the php files included.

Upvotes: 0

M1L0
M1L0

Reputation: 81

The page should be index.php not index.html in order to execute php script.

Upvotes: 0

Related Questions