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!

4
  • 1
    Possible duplicate of Wamp Server isn't executing php code Commented Feb 18, 2017 at 21:43
  • 2
    Possible duplicate of How do i render .php URL with .html extension Commented Feb 18, 2017 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 Commented Feb 18, 2017 at 23:49
  • Also make sure you run the script from a browser and not by double clicking the file name from Explorer Commented Feb 18, 2017 at 23:50

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

1 Comment

I renamed my html code index.php, and it is still printing the php code rather than "Hello world!".
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.

Comments

1

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

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.