16)PHP, set_include_path

代码展示:

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
 5     <title>网页标题</title>
 6     <meta name="keywords" content="关键字列表" />
 7     <meta name="description" content="网页描述" />
 8     <link rel="stylesheet" type="text/css" href="" />
 9     <style type="text/css"></style>
10     <script type="text/javascript"></script>
11 </head>
12 <body>
13 <?php
14     //设定配置文件中的include_path的值——代码中的设定只对当前代码有效。
15     //而且这里的设定,无需重启apache
16     set_include_path('D:\00-Code\PhpStorm\Demo\demo01');
17     
18     //更常见的做法:
19     $path = get_include_path();    //先获取系统的include_path值
20     $path_new = $path . PATH_SEPARATOR ."C:/";
21     //PATH_SEPARATOR: 是系统常量,代表目录分割符:
22     //        unix系列中,是“:”
23     //        window系列中,是“;”
24     set_include_path($path_new);    //再来设定“自己”想要加入的paht路径
25     //这样就不会破坏(丢失)原有路径设定
26     
27     echo "<p>当前工作目录:" . getcwd() .'</p>';    //getcwd()获得当前工作目录
28     
29     //相对路径:
30 //    include 'c.php';
31     
32 ?>
33 </body>
34 </html>

结果展示:

当前工作目录:D:\00-Code\PhpStorm\Demo\demo01

posted @ 2017-08-08 17:50  小油菜1  阅读(183)  评论(0编辑  收藏  举报