PHPinclude文件包含路径搜索问题的总结
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHPinclude文件包含路径搜索问题的总结,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1755字,纯文字阅读大概需要3分钟。
内容图文
![PHPinclude文件包含路径搜索问题的总结](/upload/InfoBanner/zyjiaocheng/145/839491e0aa154197808caff68f269115.jpg)
首先我们来看php官方手册中对include的文件搜索原则的描述:
Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script. E.g. if your include_path is libraries , current working directory is , you included and there is include "b.php" in that file, is first looked in and then in . If filename begins with ./ or ../ , it is looked only in the current working directory.
寻找包含文件的顺序先是在当前工作目录的相对的 include_path 下寻找,然后是当前运行脚本所在目录相对的 include_path 下寻找。例如 include_path 是 . ,当前工作目录是 ,脚本中要 include 一个 并且在该文件中有一句 include "b.php" ,则寻找 的顺序先是 ,然后是 。如果文件名以 ./ 或者 ../ 开始,则只在当前工作目录相对的 include_path 下寻找。
所以如下所示的文件结构
----a.php
----include/b.php
----include/c.php
其中a.php
<?php include 'include/b.php'; ?> ----------------------- b.php <?php include 'c.php'; include 'include/c.php'; ?>
--------------------------
c.php
<?php echo 'c.php'; ?>
--------------------------
都能正确运行,说明b.php中两种不同包含路径都是可行的,根据include寻找包含文件的方式都能找到c.php。
但是最好的方式还是使用绝对路径,如果使用了绝对路径,php内核就直接通过路径去载入文件而不用去include path逐个搜索文件,增加了代码执行效率
<?php define('ROOT_PATH',dirname(FILE)); include ROOT_PATH.'/c.php'; ?>
不同的文件包含方式,程序的执行性能比较具体可以参照此文
<script type="text/ javascript "><!-- google_ad_client = "ca-pub-1944176156128447"; /* cnblogs 首页横幅 */ google_ad_slot = "5419468456"; google_ad_width = 728; google_ad_height = 90; //--></script> <script type="text/javascript" src=" </script>
以上就是PHP include文件包含路径搜索问题的总结的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的PHPinclude文件包含路径搜索问题的总结全部内容,希望文章能够帮你解决PHPinclude文件包含路径搜索问题的总结所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。