PHP包含的脚本执行就好像它在调用者脚本的目录中一样

时间:2015-08-26 23:23:54

标签: php include

我的网站有一棵树如下:

public_html/
    index.php
    lang.fr.php
    lang.en.php
    lang.php
    description/
        index.php
        lang.fr.php
        lang.en.php
 ... (lots of directory basically like description)

所有index.php都包含lang.php,其中应包含lang.fr.phplang.en.php的每个网页版本。但是,如果我只是把

include("lang.{$lang}.php");

它包含lang.fr.php目录的lang.php

是否可以或者我必须在每个页面中添加lang.php的内容?

2 个答案:

答案 0 :(得分:1)

我认为问题在于include()只是按照它想要的那样做,包括来自它的包含文件的include_path。

您实际上可以更新PHP配置文件中的包含路径,或者更好的是,如果您愿意,可以使用set_include_path()函数在脚本期间更新include_path。最简单的解决方案是在include()中输入整个路径。

以下是一些文档:

http://php.net/manual/en/function.set-include-path.php

答案 1 :(得分:0)

在include之前将index分配给变量,并使用该变量包含相应的语言文件

相关问题