Home  >  Article  >  Backend Development  >  Path problems in php and introduction to the use of set_include_path_PHP tutorial

Path problems in php and introduction to the use of set_include_path_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:39:12848browse

first:

Path commonly used in php

Current file path: D:phpwebphp_exampleinclude_path.php

Copy code The code is as follows :

1.dirname(__FILE__); //Output D:phpwebphp_example
2.$_SERVER['SCRIPT_FILENAME']; //Output D:/phpweb/php_example/include_path.php

second:

set_include_path in php

In php, when including a file, when the include path is neither relative nor absolute (such as: include( "example.php")), will first search the directory set by include_path, and then search in the current directory. This is why many materials mention that include("./example.php") is better than include("example.php" ) reasons for high efficiency.

Method:

1.ini_set("include_path", "/usr/lib/pear"); //All versions
2.set_include_path("/usr/lib/pear" "); //version>=4.3.0
You can use the following method to add a directory to the original directory
Copy the code The code is as follows:

$path = '/usr/lib/pear';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);//The set include_path becomes Similar to /usr/lib/function;/usr/lib/pear
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/733053.htmlTechArticlefirst: Commonly used paths in php Current file path: D:phpwebphp_exampleinclude_path.php Copy the code as follows: 1.dirname (__FILE__); //Output D:phpwebphp_example 2.$_SERVER['SC...
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