[英]php not working inside html code in wampserver
Here's the thing.. I have a file named first.php containing the following code: 这就是..我有一个名为first.php的文件,其中包含以下代码:
<html>
<title>trial</title>
<head>welcome</head>
<body>
<br>
<?php
echo "hello world";
?>
</body>
</html>
However when I execute it, the php code is not interpreted. 但是,当我执行它时,不解释PHP代码。 The short open tag also seems to be on.
短开标签似乎也开启了。 I'm using wampserver.
我正在使用wampserver。 what have I missed?
我错过了什么?
It seems your server is misconfigured. 您的服务器似乎配置错误。 Your apache server must recognize .php files as a php application and evaluate the code.
您的apache服务器必须将.php文件识别为php应用程序并评估代码。
AddHandler application/x-httpd-php .php
See if you find the line above in your http.conf file. 看看你是否在http.conf文件中找到了上面这一行。
.php
file(s) under a directory say "myfirst" under /wamp/www
.php
文件放在/wamp/www
下的“myfirst”目录下 wamp icon > PHP > PHP Settings > short open tags
. wamp icon > PHP > PHP Settings > short open tags
。 Make sure it is checked. localhost/myfirst/first.php
localhost/myfirst/first.php
运行代码 hopefully it works 希望它有效
<html>
<head>
<title>trial</title>
</head>
<body>
<?php echo "hello world"; ?>
</body>
</html>
Try it with the title wrapped inside the head like it should be. 尝试将标题包裹在头部内部,就像它应该的那样。 The welcome was just floating around in no mans land, may have broken your code.
欢迎只是在没有人的土地上漂浮,可能已经破坏了你的代码。 Also, use a doctype tag -
< !html>
without the space is HTML5. 另外,使用doctype标记 -
< !html>
,空格不是HTML5。
Update Add this to a blank php file in your localhost folder. 更新将此添加到localhost文件夹中的空白php文件。
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
If you don't get a report back, it's a server config problem. 如果您没有收到报告,则是服务器配置问题。
Also make sure your putting it in htdocs
or whatever your "public" folder is. 还要确保你把它放在
htdocs
或任何你的“公共”文件夹中。
Make the changes suggested by @kcdwayne. 进行@kcdwayne建议的更改。
Now run the code from your browser, DONT doubleclick on your php file from explorer, it has to run through a browser. 现在从浏览器运行代码,不要双击浏览器中的php文件,它必须通过浏览器运行。
The 该 Tag must be inside the
标签必须在里面 Tag
标签
<head>
<title>trial</title>
</head>
<body>
<?php echo "hello world"; ?>
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.