Difference between revisions of "PHP include"
From Wiki @ Karl Jones dot com
Karl Jones (Talk | contribs) (Created page with "In PHP, the '''include''' and '''require''' keywords copies the contents of one file into other file. This is useful for making a file (such as the header section of a we...") |
Karl Jones (Talk | contribs) |
||
| Line 3: | Line 3: | ||
This is useful for making a file (such as the header section of a web page) which is included into many web pages. | This is useful for making a file (such as the header section of a web page) which is included into many web pages. | ||
| − | include is optional: if the specified file does not exist, PHP ignores the include. | + | '''include''' is optional: if the specified file does not exist, PHP ignores the include. |
| − | require is not optional: if the specified file does not exist, PHP generates an error. | + | '''require''' is not optional: if the specified file does not exist, PHP generates an error. |
| + | == Example == | ||
| + | |||
| + | Here is a PHP page named <code>message.php</code> | ||
| + | Here is a PHP page named <code>some-page.php</code>: | ||
| + | |||
| + | <pre> | ||
| + | <!DOCTYPE html> | ||
| + | <html> | ||
| + | <head> | ||
| + | <meta charset="utf-8"/> | ||
| + | <title>HTML 5 example: minimum required elements</title> | ||
| + | </head> | ||
| + | <body> | ||
| + | |||
| + | </body> | ||
| + | </html> | ||
| + | </pre> | ||
== See also == | == See also == | ||
Revision as of 20:47, 19 September 2016
In PHP, the include and require keywords copies the contents of one file into other file.
This is useful for making a file (such as the header section of a web page) which is included into many web pages.
include is optional: if the specified file does not exist, PHP ignores the include.
require is not optional: if the specified file does not exist, PHP generates an error.
Example
Here is a PHP page named message.php
Here is a PHP page named some-page.php:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>HTML 5 example: minimum required elements</title> </head> <body> </body> </html>
See also
External links
- PHP include @ php.net
- PHP include files @ w3schools.com