PHP';包括';函数错误


PHP 'include' function error

我在包含小部件时收到以下错误;

Warning: include(/includes/template/widgets/leftNavigator.php): failed to open stream: No such file or directory in C:'inetpub'wwwroot'includes'lib'widgets'class.widgets.php on line 8

当使用运行时

public static function getWidget($name) {
    ob_start
        include("/includes/template/widgets/" . strtolower($name) . ".php");
        $content = ob_get_contents();
    ob_end_clean();
    return $content;
}
....
ClassName::getWidget("leftNavigator");

但如果我也更改它:

public static function getWidget($name) {
    ob_start
        include("/includes/template/widgets/leftNavigator.php");
        $content = ob_get_contents();
    ob_end_clean();
    return $content;
}

它会很好用的。

它在使用的文件中被调用;

$this->html = preg_replace('~'{widget.('w+)'}~', Widget::getWidget("$1"), $this->html);

删除"strtolower(..)"后,我仍然收到错误。

您的文件在包含其他内容时区分大小写。你的文件有一个大写的N,strtolower($name)只是让所有字符都小写。不使用strtolower($name),只需执行$name或其他操作即可。