php not working inside html code in wampserver

烈酒焚心 提交于 2019-12-02 10:24:02

问题


Here's the thing.. I have a file named first.php containing the following code:

<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. The short open tag also seems to be on. I'm using wampserver. what have I missed?


回答1:


<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.

Update Add this to a blank php file in your localhost folder.

<?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.




回答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.




回答3:


  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




回答4:


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.




回答5:


The Tag must be inside the Tag

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



来源:https://stackoverflow.com/questions/16288018/php-not-working-inside-html-code-in-wampserver

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!