-1

I have some problem on my work. I have PHP file and want to include his file to HTML page. I used include_once()..

I just want to know, why can't include_once() run on my HTML page?

Thank you...

4
  • You are talking about a file with the suffix .htm/.html? Well those simply do not get parsed as PHP in default configuration. Commented Aug 9, 2019 at 12:15
  • is the page saved with .html or .htm file extension? Have you got the path to the include correct? Without your code and a clearer understanding of the problem we cannot help Commented Aug 9, 2019 at 12:17
  • with .html this my code <!DOCTYPE html> <html lang="en"> <head> <title>Tutorial Republic</title> </head> <body> <?php include_once("menu.html"); ?> </body> </html> Commented Aug 9, 2019 at 12:18
  • unless you have done some trickery with your webserver configuration so that it will process files saved as .html or .htm to be executed like .php files are then you cannot include php files as you are trying. Commented Aug 9, 2019 at 12:29

1 Answer 1

3

include_once is a php command and it cannot be run with HTML.

The file extension of your page must end in .php so that your server knows to read the instructions with the php processor, OR you have to have some directives written into your .htaccess file to allow the server to do some fancy work.

Save your file as .php and include the file like this.

<h1>My HTML</h1>

<?php include_once ('myFile.php') /?>

<p>More Html</p>

PHP can parse the HTML!

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

7 Comments

What if I save my file as .html?
You need to set us the server to parse .html with the php parser. The instructions are different for different server OS. What OS do you use?
I use windows...can you help me?
@8727 Don't do that, rather rename your html file to php. Because if you decide to move your page to other hosting, you can forget to set handler and you could accidentaly send your code to the visitor ...
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.