事情是这样的。我有一个名为 first.php 的文件,其中包含以下代码:
<html>
<title>trial</title>
<head>welcome</head>
<body>
<br>
<?php
echo "hello world";
?>
</body>
</html>
但是,当我执行它时,不会解释 php 代码。短开标签似乎也打开了。我正在使用 wampserver。我错过了什么?
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.
.php
file(s) under a directory say "myfirst" under /wamp/www
wamp icon > PHP > PHP Settings > short open tags
. Make sure it is checked.localhost/myfirst/first.php
hopefully it works
<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
或任何您的“公共”文件夹中。
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.
The Tag must be inside the Tag
<head>
<title>trial</title>
</head>
<body>
<?php echo "hello world"; ?>
</body>