【问题标题】:how to echo the file name that includes a file [changing page title depending on file running]如何回显包含文件的文件名[根据文件运行更改页面标题]
【发布时间】:2014-01-11 06:14:33
【问题描述】:

我尝试使用 php 预定义变量,但似乎没有任何函数适合我。

index.php、page2.php、page3.php 包含:

include 'header.php';

现在,我希望 header.php 根据调用它的文件来回显不同的标题标签。

我尝试运行 echo FILE 但回显 header.php,而不是 index.php 或 page2.php,.. 等。

有没有办法解决这个问题?

【问题讨论】:

    标签: php


    【解决方案1】:

    您可以做的是在您的每个页面(即index.phppage2.phppage3.php)上设置一个类似$title 的变量以及您想要的标题,然后像这样在header.php 中回显这个变量(例如index.php):

    $title = "Welcome Page";
    include("header.php");
    

    header.php:

    echo $title;
    

    据我所知,无法确定哪个文件A 包含文件B 中的另一个文件B。相反,确定所有包含的文件存在函数get_included_files()

    【讨论】:

    • 大声笑,这比寻找我的问题的答案要简单。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    • 1970-01-01
    • 2011-09-03
    • 1970-01-01
    相关资源
    最近更新 更多