LAMPP html或php错误?

时间:2012-02-02 18:28:45

标签: php lampp

我只是在做一个特殊的PHP。我启动了我的灯服务器,创建了html文件并将其发送到/ opt / lampp / htdocs(在phpinfo()中看到)。以下是tip.html内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> TIP OF THE DAY</title>
</head>

    <!-- start the body -->
    <body>
    <h1>Tip of the day</h1>
    <?php 
        print "<h3> Here is your tip:</h3>";
    ?>
    <div style="border-color:green; border-style: groove; border-width: 2px;">
    <?php
    readFile("tips.txt");
    ?>
    </div>
    </body>
</html>

当我打开localhost / tip.html时,它会给我一个部分输出...... 这是你的提示:“;?&gt; 有点部分解析php脚本标签的输出???任何信息为什么?

2 个答案:

答案 0 :(得分:3)

尝试查看来源。您将看到正在提供文件的整个内容,而不会评估<?php ?>标记。如果您希望PHP处理文件服务,您需要使用.php扩展名命名文件(在本例中为tip.php),或者将Web服务器配置为通过PHP处理.html文件

答案 1 :(得分:0)

看起来你不需要readFile而是file_get_contents()来将输出放在HTML文件中的那个位置。

<?php echo file_get_contents("tips.txt"); ?>