Jump to content
xisto Community
Sign in to follow this  
ghostrider

My First Php Tutorial What is PHP?

Recommended Posts

This is my first attempt at writing a PHP tutorial. Its from a while ago. What do you guys think?

 

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://forums.xisto.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 (http://forums.xisto.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.

 

<?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.

 

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 (:lol: to tell PHP that it had reached the end of the line. YOU NEED TO DO THIS FOR EVERY LINE OF CODE, OR YOU WILL GET AN ERROR.

 

You can include HTML markup inside of the print() or echo() function. For example:

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:

 

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:

 

<?PHPprint("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!

Share this post


Link to post
Share on other sites

Nice tutorial there, I like the fact it really does build from the ground up to help people who have never even heard of PHP before. Did you ever write any follow-up tutorials? If you did then you should post them here, you get credits and we got something to read that can help us out! Win-Win situation!

You should know HTML before you read my tutorial. If you don't PHP has no use to you.

True words! Although PHP isn't that hard to understand, without HTML it truly is useless!

Keep up the good work

Share this post


Link to post
Share on other sites

It's useful for begginers, sure. There are lots of people who wants to start with php and don't know where to begin because there are so much tutorials for advanced programmers...

Share this post


Link to post
Share on other sites

like???? WOAH!! I can (sorta) PHP now!!! Thankyou very much ghostrider!!!! It took me nearly a year to look through the internet to find php tuts that i can understand. Then a bloke says go to topic :XD:. Im gunna make you famous lol.

 

once again. Nice tutorial(s). (i read your others)

 

 

EDIT:

 

By the way didnt you say a tut will be released every 1-2 weeks?

Edited by hibbso (see edit history)

Share this post


Link to post
Share on other sites

like???? WOAH!! I can (sorta) PHP now!!! Thankyou very much ghostrider!!!! It took me nearly a year to look through the internet to find php tuts that i can understand. Then a bloke says go to topic :). Im gunna make you famous lol.

 

once again. Nice tutorial(s). (i read your others)

EDIT:

 

By the way didnt you say a tut will be released every 1-2 weeks?


Comon, go easy on him, hes been.. programming a lot.. i can hardly talk to him XD everytime i see him his away message is "programming"

 

so let him be :XD: hes got a lot of stuff to do (hopefully im not mixing him up with somebody..)

Share this post


Link to post
Share on other sites

Wonderful tut Ghostrider! I understand the basics of PHP now that I read your tut. Thank you for posting! I was always wondering how to code php but I always get confused in the process of learning it. Thank you again for posting.Btw, when is your next tut going to be posted?

Share this post


Link to post
Share on other sites

Btw, when is your next tut going to be posted?

Dig a little deeper into the tutorials and you will find about 8 of them by Ghostrider, all excellent sources of information.

The search feature is up on top of every page.

Share this post


Link to post
Share on other sites

Also it should be noted that PHP is OOP language!

It's actually not even really OOP. You just use classes to make it kinda OOP. It's pretty half-assed though. The newer versions are getting more OOP-ish though. :XD:

Also... Ghostrider... in the example script you don't really need to close the PHP with "PHP?>" you can simply use "?>". Like this:

<?php//bunch of php code goes here?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.