gpt4 book ai didi

php - 当文件包含在根路径(前导斜杠)中时,函数停止工作

转载 作者:行者123 更新时间:2023-12-02 07:35:14 27 4
gpt4 key购买 nike

我根目录中的 PHP 文件包括 header.php。 Header.php 包含 functions.php。我在子目录中添加新页面,因此我在 header.php 中的所有链接中添加了前导斜杠:CSS、菜单项和随后的包含到 functions.php 中。 CSS 和菜单项在此页面的子目录中工作正常,但功能不起作用。函数中没有似乎需要前导斜杠的链接。

include 和前导斜线的组合是否需要修改函数?

从根目录中的页面:

include('header.php');

从子目录中的页面:

include('/header.php');

来自 header.php:

include('/functions.php');

以及不再起作用的函数(从根目录或子目录中的页面调用):

function show_date($array_name){
if (date("Y F j",strtotime($array_name["exhibit_open"])) == date("Y F j",strtotime($array_name["exhibit_close"]))){
echo date("F j, Y",strtotime($array_name["exhibit_open"]));
}
elseif (date("Y",strtotime($array_name["exhibit_open"])) != date("Y",strtotime($array_name["exhibit_close"]))) {
$first_date_format = "F j, Y";
echo date($first_date_format,strtotime($array_name["exhibit_open"])). " - ". date("F j, Y",strtotime($array_name["exhibit_close"]));
} elseif (date("F",strtotime($array_name["exhibit_open"])) != date("F",strtotime($array_name["exhibit_close"]))){
$first_date_format = "F j";
echo date($first_date_format,strtotime($array_name["exhibit_open"])). " - ". date("F j, Y",strtotime($array_name["exhibit_close"]));
} else {
$first_date_format = "j";
echo date("F j",strtotime($array_name["exhibit_open"])). " - ". date($first_date_format,strtotime($array_name["exhibit_close"])). ", ". date("Y",strtotime($array_name["exhibit_close"]));
}

最佳答案

标准路径 101:

/path/somefile - 前导 / 将该路径结构锚定在文件系统的根目录中,例如它相当于 C:\path\somefile

path/somefile - 没有前导 /。操作系统将使用程序“当前工作”目录作为路径的基础,因此如果您在 /home/foo 中的 shell 中,则 somefile 将在 /home/foo/path/somefile 中搜索。

../一些文件.. 指的是当前工作目录的父目录,所以如果你在 /home/foo 中,那么 ../somefile 将被搜索为 /home/somefile

请注意,您可以使用无意义的路径,例如

/../../../../somefile。这是可以接受的,但毫无意义,因为你们都将路径锚定在文件系统的根目录下,然后试图超越根目录,这是不可能的。此路径相当于 /somefile 的操作。

关于php - 当文件包含在根路径(前导斜杠)中时,函数停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17239629/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com