用于 HTML 的 PHP 包含? [英] PHP Include for HTML?

查看:27
本文介绍了用于 HTML 的 PHP 包含?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have a navigational bar, an image, and a heading that I'll be including in every page of my website, so I wanted to use php include to refer to this code in several pages. However, I think I may have the syntax wrong or something because it's not rendering anything when I load it. Here are some code snippets:

<!-- sample page --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html>  
<head>  
<?php include ('headings.php'); ?>
</head>
<body>
<?php include ('navbar.php'); ?>
<?php include ('image.php'); ?> 
</body>
</html>

navbar.php

    <?php 

    echo '<ul id="nav">
        <li>
            <a href="Home.html">Home</a>
        </li>
        <li>
            <a>About Me</a>
            <ul>
                <li>
                    <a href="Career.html">Career</a>
                </li>
                <li>
                    <a href="Coding.html">Coding</a>
                </li>
                <li>
                    <a href="Personal.html">Personal</a>
                </li>
            </ul>
        </li>
        <li>
            <a href="Travels.html">Travel</a>
        </li>
        <li>
            <a href="Contact.html">Contact</a>
        </li>
    </ul>';

    ?>

Thanks for helping!

解决方案

You can use php code in files with extension .php and only there (iff other is not defined in your server settings).

Just rename your file *.html to *.php


If you want to allow php code processing in files of different format, you have two options to do that:

1) Modifying httpd.conf to allow this for all projects on your server, by adding:

AddHandler application/x-httpd-php .htm .html

2) Creating .htaccess file in your separate project top directory with:

<Files />
    AddType application/x-httpd-php .html
</Files>

For second option you need to allow use of .htaccess files in your httpd.conf, by adding the following settings:

AllowOverride All
AccessFileName .htaccess

*that is correct for Apache HTTP Server

这篇关于用于 HTML 的 PHP 包含?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆