1

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?

dhofstet
  • 9,934
  • 1
  • 36
  • 37
Ramya259
  • 43
  • 1
  • 8

5 Answers5

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.

Jose Areas
  • 719
  • 3
  • 11
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

ritesh
  • 907
  • 3
  • 11
  • 31
Ram Ganti
  • 21
  • 1
0
<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.

Casey Dwayne
  • 2,142
  • 1
  • 17
  • 32
  • Also, make sure your address is `http://localhost/yourfolder/yourfile.php`, not just opening the file from the file system. – Casey Dwayne Apr 29 '13 at 21:43
  • Oops,my bad. you were right. I was just opening it from the file system. Now it worked. Ha.. Thanks a lot.. – Ramya259 May 02 '13 at 08:41
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.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
0

The Tag must be inside the Tag

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

Alaeddine
  • 1,571
  • 2
  • 22
  • 46