Question

I just installed XAMPP on my windows 7 machine. Had to change the HTTP ports because 80 and 443 were taken. No problem there.

When I access http:// localhost /xampp/phpinfo.php I get the PHP info page so I know PHP is up and running. If i create a new file called test.php containing:

<!DOCTYPE html>

<html>
  <head>
    <title>Hello</title>
  </head>
  <body>
  <h1> TEST </h1>
    <pre>
      <? print("Hello PHP."); ?>
    </pre>
  </body>
</html>

and access http:// localhost :81/xampp/test.php all I get is

TEST

the PGP tag doews not get processed. "Hello PHP" does not show and when I have Crome show the page source (view-source:http:// localhost :81/xampp/test.php) I get:

<!DOCTYPE html>

<html>
  <head>
    <title>Hello</title>
  </head>
  <body>
  <h1> TEST </h1>
    <pre>
      <? print("Hello PHP."); ?>
    </pre>
  </body>
</html>

So, same directory, one file processes PHP, the one next to it does not.

I'm pretty sure I have to change something on the new file. Maybe a permission? Maybe a file attribute?

Please help.

Was it helpful?

Solution

Can you try using

 <?php print("Hello PHP."); ?>

OR

 <?php echo "Hello PHP."; ?>

<?php ?> or <?= ?> - standard tags

<? ?> - short tags, need short_open_tag enabled in php.ini.

You can find the currently loaded php.ini file location using <?php phpinfo();?>

When PHP parses a file, it looks for opening and closing tags, which are which tell PHP to start and stop interpreting the code between them. Parsing in this manner allows PHP to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser.

PHP also allows for short open tags (which are discouraged because they are only available if enabled with short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option.

OTHER TIPS

You shouldn't run your php file into the xampp folder but instead, in the htdocs folder. In default it is located inside your XAMPP folder. (Common directory C:/xampp/htdocs)

From inside htdocs, you can create a folder which can serve as your temporary host name. For example, the folder you created would be named as site, its url would be localhost/site.

For it to have a default file, you have to name your php as index.php so that when it runs site, it would run the index as the default but if you stick to test.php, you would do it like this:

localhost/site/test.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top