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:

$Links = array("index.php", "page1.php", "page2.php");
$Text = array("Home", "page1", "page2");
$ReqPage = (explode('/', $_SERVER['SCRIPT_NAME']));
echo $ReqPage[2];
<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>
$Nav .= "</ul>


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.


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

    解决 无用
    打赏 举报

相关推荐 更多相似问题