I am new to PHP, just downloaded it, and wrote a "Hello, World!" program:
<html>
<body>
<?php
$fileN开发者_JAVA技巧ame = "test.jpg";
$txt = "Hello, World!";
echo $txt;
?>
</body>
</html>
But it doesn't work. I named the file test.php
and opened it with Firefox and nothing was displayed.
You'll have to pass it through a webserver of some kind, for example IIS or Apache, for it to work.
PHP is a server-side 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:
- WAMP - http://www.wampserver.com/en/ (Windows)
- XAMPP - http://www.apachefriends.org/en/xampp.html - (Windows, Mac, and Linux)
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).
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.
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.
If you have command-line PHP installed, you should be able to enter:
php test.php
to invoke PHP to run your program and display the output on the console.
You need a webserver to view the PHP program like XAMPP or WAMP. If you are using XAMPP, put your file in htdocs and then access your file from any browser like Google Chorme, Firefox or Internet Explorer by typing localhost/foldername/yourfile.php
, in your case localhost/test.php
.
Do you have a local server installed? PHP is a server-side scripting language, so it cannot just be run like a normal HTML file.
Try watching the first few videos on the New Boston's PHP series. They show you simply how to download, install and use a local server to run your PHP on.
精彩评论