php不起作用,PHP包含功能不起作用

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

发生的事情是,如果我把在原始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.

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

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

标签:include,php,function

来源: https://codeday.me/bug/20191030/1968939.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值