Leilin Peng Share: PHP include file

  PHP include and require statements

  In PHP, you can insert the contents of a file in the file before the server executes the PHP file.

  include and require statements for inserting written in other documents useful code execution flow.

  include and require different treatment in addition to the wrong way, in other respects are the same:

  require generates a fatal error (E_COMPILE_ERROR), after the error script execution stops.

  include generating a warning (E_WARNING), the script will continue execution after an error occurred.

  So, if you want to continue, the output to the user, even if it contains file is missing, then please use include. Otherwise, in the framework, CMS or complex application programming in PHP, always use require references to key documents execution flow. This helps improve the safety and integrity of the application, in the case of an accidental loss of key documents.

  Save a document that contains a lot of work. This means that you can create a standard header for all pages, footer, or menu file. Then, when you need to update the page header, you can simply update the page header contains files.

  grammar

  include 'filename';

  or

  require 'filename';

  PHP include and require statements

  Examples basis

  Suppose you have a standard header file, called "header.php". For reference this header file in a page, use the include / require:

  Welcome to my home page!

  Some text.

  Examples

  Suppose we have a standard menu file for use in all pages.

  "menu.php":

  echo 'Home

  HTML Tutorial

  PHP Tutorial ';

  All pages of the site should refer to the file menu. The following are the specific practices:

  Welcome to my home page!

  Some text.

  Example 3

  Suppose we have a definition of a variable that contains the file ( "vars.php"):

  $color='red';

  $car='BMW';

  ?>

  These variables can be used in the call file:

  Welcome to my home page!

  include 'vars.php';

  echo "I have a $color $car"; // I have a red BMW

  ?>

  View all PHP tutorial article: https://www.codercto.com/courses/l/5.html (edit: Leilin Peng Source: network intrusion deleted)

Guess you like

Origin www.cnblogs.com/linpeng1/p/11058195.html