dongyuedaochen8415 2014-04-16 16:34
浏览 220
已采纳

PHP Include函数不显示任何内容

I'm pretty new to web development and I am trying to learn by trying to develop a website of course. However, I am hitting an issue, I don't get why my include function in PHP is not working.

My 'menu.php' file contains:

<?php
echo '
            <li><a href="#" class="current">Home</a></li>
            <li><a href="#">button1</a></li>
            <li><a href="#">button2</a></li>            
            <li><a href="#">button3</a></li>  
            <li><a href="#">button4</a></li> 
            <li><a href="#">button5</a></li> ';
    ?>

My html file contains the following:

...
<nav>
   <ul>
      <?php include 'menu.php'; ?>
   </ul>
</nav> 
...

What am I missing? If I copy the list items from my .php to my .html, it works properly. It works:

 ...
    <nav>
       <ul>
                <li><a href="#" class="current">Home</a></li>
                <li><a href="#">button1</a></li>
                <li><a href="#">button2</a></li>            
                <li><a href="#">button3</a></li>  
                <li><a href="#">button4</a></li> 
                <li><a href="#">button5</a></li> 
       </ul>
    </nav> 
 ...

Thank you in advance.

  • 写回答

2条回答 默认 最新

  • dqn8235 2014-04-16 16:37
    关注

    When you say:

    My html file contains the following:

    Do you mean that you have a file like index.html? Because that means that PHP is not being parsed. All that's happening is that you have a weird <?php> element that gets silently ignored as invalid HTML.

    Try renaming your file to index.php instead.

    As an aside, you should always use the browser's View Source option before saying it doesn't do anything ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?