views:

178

answers:

5

I'm kind of confused.

I would put all the HTML for the menu in a .php file and have the engine require it right?

A: 

Dunno what do you call "loads correctly", but yes, you can put all the HTML for the menu in a .php file and have the engine require it

Col. Shrapnel
+1  A: 

According to the manual, the require() function will produce a fatal error if it cannot find the required file. So, if you require() the menu and the menu file is not present, you page will not show.
But if the menu file is found and contains errors, the page will show them.

Davide Gualano
+1  A: 

require_once(), and more specifically require() in general, will throw a fatal error (which will cause the page to stop loading) if the file does not exist. If there is an error in the file itself, require() will not change what happens. require_once() (and include_once()) are used in the case that you might have two or more files that need the same file to work. Basically, the _once functions will not let the same file be included multiple times (which is good, because you cannot redeclare functions and such).

Chibu
+1  A: 

Instead of using require() to load blocks of HTML, just use:

print file_get_contents('html/menu.html');
TravisO
readfile() then
Col. Shrapnel
Why use a complex function and a language construct to replace a perfectly acceptable language construct?
Álvaro G. Vicario
Why should I use this? :S
Serg
Because if you readfile() you don't have to parse what you have required, it will be faster.
Kris Erickson
+1  A: 

These are the four basic possibilities:

  • require_... stops the script if there's an error
  • include_... continues execution if there's an error
  • ..._once only loads the file the first time you use it
  • ..._nothing loads the file every time you use it

Of course, in normal circumstances, there should never be errors ;-)

Álvaro G. Vicario