微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP包含功能不起作用

我正在尝试开发一个网站.我希望将用PHP编写的网站的不同部分放在不同的文件中.例如“ posts.PHP”,“ recents.PHP”等.我正在尝试使用功能“ include”来包含目录“ / codes /”中的文件.但这是行不通的.

发生的事情是,如果我把<?PHP include'/codes/posts.PHP'?>在原始HTML页面的中间(该页面PHP格式保存).添加的行之前的代码部分正常工作,但是添加的行之后的代码部分消失了.不知道为什么.我究竟做错了什么?

解决方法:

解决分号问题后,还应考虑:

If a path is defined — whether absolute (starting with a drive letter or \ on Windows, or / on Unix/Linux systems) or relative to the current directory (starting with . or ..) — the include_path will be ignored altogether. For example, if a filename begins with ../, the parser will look in the parent directory to find the requested file.

form the PHP docs

因此要么包含“ ./codes/posts.PHP”;或包含’codes / posts.PHP’,第一个版本相对于当前工作目录查找文件,第二个版本使用包含路径.

PS:最好使用require_once或include_once,以避免多次包含相同的函数/类定义,这会引起问题(重新声明函数)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐