tags:

views:

117

answers:

4

I am new to PHP - just downloaded it and wrote hello world program:

<html>
<body>

<?php

$fileName = "test.jpg"; 

$txt="Hello World!";
echo $txt;

?>

</body>
</html>

But it doesnt work. I named the file test.php and opened it with Firefox and nothing was displayed.

+6  A: 

You need to have a webserver that you open it through. Simply entering file:///whatever.php does not work, because the file is not parsed by PHP then.

There are several web servers you can chose from, but my advice is Apache, the worlds most popular webserver. I have it running on my Windows XP laptop along with PHP, and it's easy to install and setup, and works great. There are lots of modules that can be installed later if you need them. It's also free, not only as in free beer, but also as in open source.

Marius
-1. His file is fine. No need to strip the HTML.
phidah
He edited his question after I answered his question.
Marius
his answer is legitimate, why give -1 ?
He edited it :)
phidah
I aggree with installing apache, but as a beginner, you should go for wamp or apache2triad until you fully learn what s going on. that s what i think.
+5  A: 

You will need to install a webserver on your machine to make it work. Take a look at Xampp at http://www.apachefriends.org/en/index.html

hoball
+10  A: 

You'll have to pass it through a webserver of some kind, for example IIS or Apache, for it to work.

PHP is a serverside language, thus you can't just open the PHP file in a browser. Instead, try googling some free php hosts, and upload your files there.

You could for example go for these solutions that will provide you with what you need:

Those solutions will install Apache, MySQL and PHP and allow you to play locally with PHP development. Later on, if you want to deploy your code, you will have to find an external host (or host it on your own computer).

phidah
You are right, I didnt open it with a websever - the short online tutorial didnt say anything about that. Will try WAMP. Thanks a lot guys!
LikeToCode
+1  A: 

If you have command line PHP installed, you should be able to enter:

php hello.php

to invoke php to run your program (substitute your actual file name if it isn't "hello.php", of course) .

GreenMatt