Intro To PHP
Tutorial 1 - What is PHP?
Released 2/20/07
By Chris Feilbach aka GhostRider
Contact Info:
E-mail: assembler7@gmail.com
AIM: emptybinder78
Yahoo: drunkonmarshmellows
Website: http://www.ghostrider.trap17.com
Hello, and thank you for choosing my tutorial. If you are completely new to PHP, this tutorial will teach you all the basics, and if you are not it will serve as an excellent reference for you. I will release the next section of my tutorial every 1 to 2 weeks. All of the basics will be covered; in this set of tutorials you will learn everything a PHP coder needs to know, including how to use MySQL (a database server), and how to handle data from forms. If you want to learn about something in particular, go ahead and contact me and I will see what I can do. You also should contact me if you have any questions about anything I write in my tutorials.
You should know HTML before you read my tutorial. If you don't PHP has no use to you. Go learn it and then come back. It does not take long to learn how. http://www.w3schools.com is a great resource.
PHP stands for Hypertext Preprocessor, which is a bunch of big words that means it runs a script, or a bunch of PHP that you write, and then outputs something to the person viewing your web page. PHP is very powerful; it can output more than just HTML. You can also create images, and various other things using PHP and output them to your user's browser.
PHP is a server-side application, meaning that all of the processing is done on the server, or the computer that sends the data to your user. Things such as HTML and JavaScript are client-side applications, meaning that the code is sent to the computer viewing it and then processed. The fact that PHP is server-side means that any computer with a web browser can view its output.
PHP requires a server, such as Apache, to run. I run all of my scripts that I make off of my website. You can either get webspace that supports PHP (www.trap17.com is where I get my totally free webspace), or simply download your own webserver on your computer. I don't have a preference for a server for testing PHP. Anything that supports it will do.
PHP files are placed in the same directory that your html files and other files are stored. For my site, I place them in the public_html. PHP files can be written in ANY text editor. I primarily use Linux, so I use KWrite to write my PHP files, but Notepad is probably the best editor for Windows. I prefer KWrite over Notepad because it color codes your PHP, making it much easier to read, and also displays line numbers if you press F11, a feature that makes debugging PHP much easier.
I have been programming in a variety of languages for 10 years now, and every other decent programmer will tell you the same as I am about to. Take small steps with learning ANY language, don't be discouraged if it doesn't work right away (it usually doesn't when your new to it), and enjoy your success. Show some creativity with your work and make it yours. Have some patience at first, as I said above, things won't always work the first (or second, or third, and so on) times, especcally when your new. If worst comes to worst e-mail me your code and I'll help you out the best I can.
Now that you've listened to all of that, I think its about time we actually coded something. First we need to learn a little bit about the syntax of PHP. I'll walk you through it step by step.
First, to tell the server that we are beginning PHP code, we need to put this.
CODE
<?PHP
The server is now proccessing PHP. You no longer can just write HTML, you will cause an error if you do. To send stuff use the print() or echo() functions. Both of them do exactly the same job.
CODE
print("PHP is awesome!");
This command sends PHP is awesome! to the user's web browser. "PHP is awesome!" is something called an argument, or something that a function needs to do its work. You need to place strings, or things with characters, in quotes "". End it with a parenthesis, and use a semi-colon (
You can include HTML markup inside of the print() or echo() function. For example:
CODE
print("<br><font color=red>Red is my favorite color.</font>");
Will print out Red is my favorite color., in red.
End your php code with this:
CODE
PHP?>
I have one more thing to introduce to you today. You can add comments to your code to help yourself and other people that read it understand it. Anything that follows two forward slash marks (//) is considered a comment. PHP will not consider them code.
The whole thing looks like this:
CODE
<?PHP
print("PHP is awesome!"); // The two lines mean that this is a comment.
// PHP completely ignores //. Commenting your code is very imporant, so do it!
print("<br><font color=red>Red is my favorite color.</font>");
PHP?>
print("PHP is awesome!"); // The two lines mean that this is a comment.
// PHP completely ignores //. Commenting your code is very imporant, so do it!
print("<br><font color=red>Red is my favorite color.</font>");
PHP?>
Have some fun with this. Print whatever your heart desires. Next tutorial we will go into variables, and shortly after that we will cover forms.
Happy coding!

