php标签不工作/字符串不显示

时间:2012-07-16 12:01:03

标签: php html

我正在尝试用PHP编程,但php标签不起作用: 我相信我的代码中没有错误:

<html>
    <head>
        <?php 
            $test = "Gumagana ako :P";
            echo "$test";
        ?>
        <title>My First PHP</title>
    </head>
    <body>
        My Test String is <?php echo $test; ">
    </body>
</html>

您认为这是什么问题?仅供参考,我使用的是xampp。

6 个答案:

答案 0 :(得分:4)

确保您的文件扩展名为.php及其在Xampp文件夹的htdocs文件夹中。并且还要确保Apache服务正常运行。

并确保您正在浏览http://localhost/yourfile.php

<html>
    <head>
        <?php 
            $test = "Gumagana ako :P";
            echo "$test";
        ?>
        <title>My First PHP</title>
    </head>
    <body>
        My Test String is <?php echo $test; ?>
    </body>
</html>

答案 1 :(得分:3)

你在关闭你的PHP时输了一个错字。

My Test String is <?php echo $test; ">

像这样关闭你的php:

My Test String is <?php echo $test; ?>

否则php会尝试将以下内容解释为php,这会产生错误:

"> </body> </html>

答案 2 :(得分:1)

缺少PHP结束标记或问题已替换为双引号:

 My Test String is <?php echo $test; ?>

答案 3 :(得分:1)

My Test String is <?php echo $test; ?> //标签未关闭

答案 4 :(得分:1)

  <body>


       My Test String is <?php echo $test; ">


  </body>

有misteck

My Test String is <?php echo $test; ?>

请检查

答案 5 :(得分:1)

就这样写: -

My Test String is <?php echo $test;?>
相关问题