1

事情是这样的。我有一个名为 first.php 的文件,其中包含以下代码:

<html>
    <title>trial</title>
    <head>welcome</head>
    <body>
    <br>
    <?php
    echo "hello world";
    ?>
    </body>
</html>

但是,当我执行它时,不会解释 php 代码。短开标签似乎也打开了。我正在使用 wampserver。我错过了什么?

4

5 回答 5

2

It seems your server is misconfigured. Your apache server must recognize .php files as a php application and evaluate the code.

AddHandler application/x-httpd-php .php

See if you find the line above in your http.conf file.

于 2013-04-29T20:58:25.547 回答
1
  1. make sure you place the .php file(s) under a directory say "myfirst" under /wamp/www
  2. make sure the wamp server is online (shows green icon)
  3. Enable short tags click on wamp icon > PHP > PHP Settings > short open tags. Make sure it is checked.
  4. run the code in browser as localhost/myfirst/first.php

hopefully it works

于 2014-03-19T04:18:10.803 回答
0
<html>
  <head>    
    <title>trial</title>
  </head>
  <body>
    <?php echo "hello world"; ?>
  </body>
</html>

尝试将标题包裹在头部内,就像它应该的那样。欢迎只是漂浮在无人区,可能已经破坏了您的代码。此外,使用 doctype 标签 -< !html>没有空格是 HTML5。

更新 将此添加到 localhost 文件夹中的空白 php 文件中。

<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>

如果您没有收到报告,那就是服务器配置问题。

还要确保将其放入htdocs或任何您的“公共”文件夹中。

于 2013-04-29T20:55:00.510 回答
0

Make the changes suggested by @kcdwayne.

Now run the code from your browser, DONT doubleclick on your php file from explorer, it has to run through a browser.

于 2013-04-29T21:38:54.483 回答
0

The Tag must be inside the Tag

<head> 
   <title>trial</title>
</head>
<body>
 <?php echo "hello world"; ?>
</body>

于 2014-04-06T10:15:48.270 回答