-1

I'm trying to learn PHP through codecademy.org and I can't understand why the following code, when saved in as helloworld.php, returns no text. I tried in Internet Explorer and in FireFox, but nothing. I also opened the .php file in notepad and it looks fine, uncorrupted. What's going on here? I followed codecademy's instructions exactly, and the code works in the codecademy previewer. Code:

<html>
<head>
    <title>Hello World</title>
</head>
<body>
        <p><?php echo "Hello World!"; ?></p>
</body>
</html>
  • Save the file extension as `.php` instead of `.html` – Shankar Narayana Damodaran Jan 12 '14 at 13:35
  • 2
    You need a server to run PHP. It can't directly run in a browser. – Talha Masood Jan 12 '14 at 13:35
  • possible duplicate of [How to run php files on my computer](http://stackoverflow.com/questions/8580273/how-to-run-php-files-on-my-computer) – mario Jan 12 '14 at 13:39
  • It's not a duplicate. If the downvote is because of this suspicion, then I think it is unjustified. I understand now that I need to upload helloworld.php to a server though. Will accept answer once stackoverflow timer mechanism allows me to. – user2811095 Jan 12 '14 at 13:46
  • To test whether your server is working or not,please insert any html elements like images and run the file again... And if it works,then you have no server there.. You could use wamp or xampp... And if you have one already, please check whether your server is off or its port been used by any other clients like skype.. – Vaisakh Pc Jan 12 '14 at 13:46

5 Answers5

0

Have you put the file on a server with PHP? The code has to be executed by PHP interpreter, and the browser itself doesn't have one.

The easiest solution is probably setting up a server locally, on your computer. I recommend XAMPP (for Windows), it's easy to install and use.

PiotrK
  • 1,502
  • 1
  • 15
  • 33
0

you need a server (apache, php, ...) to run php. look at zend server, xampp, ... its quite easy to setup.

timg
  • 501
  • 2
  • 4
  • 13
0

You should have a web server and php installed in your computer to get it run. Try wamp server: http://wampserver.com/ It is a very easy to use solution for windows. You just install it and it handles everything else by itself!

If you already have a server installed, make sure you put the files on the "www" directory!

0

You need a webserver parsing your php-file. Try to use XAMPP.

tjati
  • 5,761
  • 4
  • 41
  • 56
0

you should put your code into php file make helloworld.php file
and put in wamp www folder and run with wamp server.
for hello world program in php just follow this tutorial
but before that you should have wamp server or xamp server on your pc
(wamp/xmap are open source software's and easily can found on google)
your 1st php program code:-

<?php
echo "hello world";
?>

output:- hello world Helping Step by Step Tutorial :https://www.youtube.com/watch?v=7qtqzhdEX-c
after this tutorial you can able to move other intermediate level programs of php.

Hassan Saeed
  • 6,326
  • 1
  • 39
  • 37