1

我正在尝试用 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。

4

6 回答 6

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>
于 2012-07-16T12:06:56.483 回答
3

您在关闭 php.ini 时打错了字。

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

像这样关闭你的php:

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

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

"> </body> </html>
于 2012-07-16T12:03:28.693 回答
1

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

 My Test String is <?php echo $test; ?>
于 2012-07-16T12:03:43.653 回答
1

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

于 2012-07-16T12:04:37.960 回答
1
  <body>


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


  </body>

有误会

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

请检查一下

于 2012-07-16T12:04:50.120 回答
1

就这样写:-

My Test String is <?php echo $test;?>
于 2012-07-16T12:05:01.967 回答