PHP 包括不工作?我正在使用文件路径打开 chrome

PHP Include not working? I am using the file path to open on chrome

我想使用 php 包含添加导航栏,但我在 navBar.php 文件中循环使用它:

<?php
$Links = array("index.php", "page1.php", "page2.php");
$Text = array("Home", "page1", "page2");
$ReqPage = (explode('/', $_SERVER['SCRIPT_NAME']));
echo $ReqPage[2];
$Nav="\r\n<div id=\"navwrapper\">\r\n
          <div id=\"nav\">\r\n
          <ul id=\"navstuff\">\r\n";
$j = 0;
foreach($Links as $ALink){
    if ($ALink == $ReqPage){
        $Nav .= "<li class=\"selected\"><a href=\"#\">";
    } else{
        $Nav .= "<li><a href=\"$ALink\">";
    }
    $Nav .= "$Text[$j]</a></li>\r\n";
    $j++;
}
$Nav .= "</ul>\r\n
        </div>\r\n
        </div>\r\n";
echo $Nav;
?>

我的 index.php 文件中有它 <?php include("navBar.php"); ?>。它没有显示任何内容。是因为我没有 运行 关闭服务器吗?目前,我只需在 Chrome 中输入文件路径即可打开文件。我必须为此使用服务器吗?另外,如果我必须使用服务器,有哪些适合我电脑的好服务器(我不想花钱购买大型外部服务器)?

是的,您需要 运行 安装了 php 功能的服务器软件。

我会推荐 Apache+PHP,它将 运行 在您的本地计算机上使用,并且不会花费您任何费用。

搜索新手安装指南。

编辑:

其实你只需要PHP。它有一个 inbuilt web server,非常适合在本地机器上进行测试。