Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

dravu2000
Guest
In this tutorial, I will bring you into the PHP language and teach you one of the basic commands. :)

To start off, PHP scripts must be used in PHP files. You can start off by creating a file called test.php or really anything as long as it has the ".php" extension at the end.

Open the file in Notepad or whatever program you prefer and type this:
<?php

?>

This sets the base for your PHP script. Much like other coding languages, this tells where it starts and stops so the software knows how to interpret certain things.

To start off our script, we'll do the basic thing of many programming languages. And that is, to create a "Hello World!" statement. In PHP, the most common ways of outputting content to the screen is using the Echo or Print commands. PHP is a server-side language, so you can't just type something in the script and it be immediately outputted. That's where Echo and Print come in. Since I'm more comfortable using Echo, I shall use it, but you can replace it with Print and still get the same results. Make your code look like this:
<?php

echo "Hello World!";

?>

Note again that the actual coding goes between the "<?php" and "?>". If you upload this file to a PHP-enabled host and view it, you'll see "Hello World!" on the page. Wanna see something neat? Try viewing the source. The only thing you'll see is what the PHP outputted to your browser. The rest was kept server-side.

If you notice, at the end of the 'Echo' line is a semicolon (;). Every command line must end like that or else it'll fail. That basically tells the server to stop there and start new with the next line. Otherwise, it'll think the first line and all the lines after it (until it reaches a semicolon or other break) is apart of the same command and will throw errors out at you because it simply won't work.

Well I hope that helped you get started. If you have any questions or anything, don't hesitate to ask. =3


Last Edit: Jun 23, 2007 20:00:48 GMT by Guest

aeontrix

aeontrix Avatar

*
New Member

1


October 2008
Why do you need the

";"

after "Hello World!"?

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
Wow

newBookmarkLockedFalling