1

I have an HTML script ("index.html") which includes the follow PHP code:

< ?php
include ('footer.php');
?>

The PHP script ("footer.php") contains the following code:

<?php
   echo "Hello world!";
?>

When I run :index.html: on the WampServer as a localhost, the PHP code from "index.html: is displayed. How do I display "Hello world!" from "footer.php"?

Thank you!

kkj
  • 45
  • 8
  • 1
    Possible duplicate of [Wamp Server isn't executing php code](http://stackoverflow.com/questions/10600564/wamp-server-isnt-executing-php-code) – Matt S Feb 18 '17 at 21:43
  • 2
    Possible duplicate of [How do i render .php URL with .html extension](http://stackoverflow.com/questions/5309490/how-do-i-render-php-url-with-html-extension) – chris85 Feb 18 '17 at 21:45
  • A file is only passed to the PHP coliler if it ends with an extension of `.php` a file with the `.html` extension will not (by default) get passed through the PHP compiler – RiggsFolly Feb 18 '17 at 23:49
  • Also make sure you run the script from a browser and not by double clicking the file name from Explorer – RiggsFolly Feb 18 '17 at 23:50

4 Answers4

2

I have an HTML script ("index.html") which includes the follow PHP code:

This is wrong. Your index.html will not understand PHP Code. Rename your html code index.html to index.php.

Hope this will help

muya.dev
  • 966
  • 1
  • 13
  • 34
  • I renamed my html code index.php, and it is still printing the php code rather than "Hello world!". – kkj Feb 18 '17 at 22:43
1

To include other php scripts your index page should be with php extension (index.php) instead of index.html

rango
  • 609
  • 1
  • 7
  • 23
1

I supposed that you save php file that you want to include as footer.php in the same directory where index.php exists. Now where you want to include footer.php, include this code at the desired location.

<?php
    include ('footer.php');
?>

I think that space between < and ? in index.php was creating problem.

Edit : Exactly space between < and ? in index.php is creating problem and printing php code.

Community
  • 1
  • 1
Anshuman
  • 758
  • 7
  • 23
0

Left click on the Wamp icon in the bottom right tray of your computer >> Apache >> left click on httpd.conf >> scroll 2/3rd's the way down >> add AddType application/x-httpd-php .html to as shown below >> save and close it >> restart Wamp >> Done!

<IfModule mime_module>
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php3
    AddType application/x-httpd-php .html
</IfModule>