duanque19820925 2016-01-12 05:27 采纳率: 0%
浏览 72
已采纳

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

I want to add a nav bar using php include, but I have it in a loop in the navBar.php file:

<?php
$Links = array("index.php", "page1.php", "page2.php");
$Text = array("Home", "page1", "page2");
$ReqPage = (explode('/', $_SERVER['SCRIPT_NAME']));
echo $ReqPage[2];
$Nav="
<div id=\"navwrapper\">

          <div id=\"nav\">

          <ul id=\"navstuff\">
";
$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>
";
    $j++;
}
$Nav .= "</ul>

        </div>

        </div>
";
echo $Nav;
?>

I have it in my index.php file as <?php include("navBar.php"); ?>. It is not showing anything. Is it because I am not running off of a server? Currently I am opening the file by just typing in the file path into Chrome. Do I have to use a server for this? Also, If I have to use a server, what are some good ones for my computer (I don't want to pay money for large external servers)?

  • 写回答

1条回答 默认 最新

  • duanji1924 2016-01-12 05:42
    关注

    Yes you need to run server software that has php functionality installed.

    I would recommend Apache+PHP which will run on your local machine and won't cost you anything.

    Search for an installation guide for beginners.

    EDIT:

    Actually all you need is PHP. It has an inbuilt web server which would be perfect for testing on a local machine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?