Home  >  Article  >  Backend Development  >  Four ways to import files in php

Four ways to import files in php

angryTom
angryTomOriginal
2019-08-22 15:04:216121browse

Four ways to import files in php

The examples in this article describe four ways to introduce files in PHP. Share it with everyone for your reference, the details are as follows:

Recommended tutorial: PHP video tutorial

##1 .include

Includes and runs the specified file. The included file is first searched according to the path given by the parameter. If no directory (only the file name) is given, it is searched according to the directory specified by include_path. If the file is not found under include_path, include will finally search in the directory where the calling script file is located and the current working directory. If the file is not found at the end, the include structure will issue a warning. This is different from require, which will issue a fatal error

If a path is defined - whether it is an absolute path (starting with a drive letter or ** under Windows , starting with / under Unix/Linux) or a relative path to the current directory (starting with . or ..) - include_path will be completely ignored. For example, if a file starts with ../, the parser will look for the file in the parent directory of the current directory.

2.include_once

Include and run the specified file during script execution. The only difference is that if the file has already been included, it will not be included again. As the name of this statement implies, it will only be included once.

3.require

require and include are almost identical, except for the way they handle failures. require generates an E_COMPILE_ERROR level error on error. In other words, it will cause the script to abort and include will only generate a warning (E_WARNING), and the script will continue to run.

4.require_once

The require_once statement is exactly the same as the require statement. The only difference is that PHP will check whether the file has already been included. If so, it will not include it again. .

The above is the detailed content of Four ways to import files in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn