blenderNetworkpatreonblender-logosdheartuserthtimesbookphotopencilmap-markerchevron-rightbancommentcommentstwitterfacebookrsschainnavicongoogle-plusenvelopelinkedinmail-replycalendar-otumblrredditstumbleuponshare-altbloggerflattrflag

PHP Tutorial

PHP Tutorial

Postby djm » October 3rd, 2010, 2:59 am

Well, as you can see I've made a PHP tutorial. Mainly it was requested by 3LD since he didn't know what PHP was.
It's only the basics; Variables, basic commands, combinations, how/when/why and some notes on what you should keep in mind while scripting in PHP (or any other language in that matter).

I hope this will help at least some of you guys!
Link (for those who are to lazy to go to the tutorial tab); http://www.darkscarab.com/tutorials/user_view.php?title=nNqN7g1QGNWfd8Q6KLXL6fJ57aJCyO

UPDATE (By Irascibleone): In an attempt to make the main part of DS graphics related only, this tutorial has been shifted into the forum. Or more specifically, right here:

PHP Tutorial - Basic Calculations and Variables
SHOW SPOILER
Contents:

  • Step 1: Software and Local Hosting
  • Step 2: The build, HTML + PHP.
  • Step 3: Variables, why, when, how?
  • Step 4: Combinations between commands
  • Step 5: Scripting - What to keep in mind
  • Step 6: Finish - The results



Colors Representing Commands:

HTML-tag
<?php Insert script here ?>
echo "What's inside the echo command"
Variables - $variable
#Comments, //Comments, /*Comments */

---------------------------------------------------------------------

Step 1: Software and Local Hosting

When using PHP you need to keep in mind that having a software which can colorize the different tags/scripts as well as a software that can host and read the PHP-scripts is quite useful. And for this we are going to use the "AMP" series and a simple web developer software such as Dreamweaver, Smultron or any other software that you'd prefer instead.

The "AMP" series is a series of softwares which creates a local server on your computer which only you can connect to; "http://localhost:8888/".

If you're using Windows, download "WAMP".
If you're using Mac, Download "MAMP".
If you're using Linux, Download "LAMP".

They are all the same, but for different Operation Systems.

and as you probably will notice, I'm using Mac and therefor I'm also using MAMP (Mac-AMP). "AMP" is easily configured - All you need to do is install it and then start it. It will automatically host a server for you. When you want to check what you have done with PHP, simply save your file as "anything.php" (without the quotes) inside the htdocs folder in the WAMP(windows) or MAMP (Mac) or LAMP (Linux) directory. When you have done this, simply open your browser and enter the following; http://localhost:8888/anything.php

Now you have established your local server and can now move on to the actual scripting!

Image

Step 2: The build - HTML + PHP

If you want to create your own website, you need HTML. To make your PHP work on your website you need to add a simple PHP tag to your HTML.
For example;

Image

And now we add the PHP tag. Make sure to add it within the php tags!

Code: Select all
<?php
Insert script here
Insert script here
?>


Everything related to PHP will be put inside this PHP tag. (NOTE* you can have more than one PHP tag, but we will only use one for now).

Step 3: Variables, why, when, how?

Variables - $Variable - A command used for storing valuable information. Very usefull for passwords, calculations and very long commands.

Why - A simple way of making the programming timelapse shorter as well as making it better, more clean.

When - Every time you need to store any kind of information.

How - Add $ and then a name; $djm, or $spaghetti or anything else you like to call it. It doesn't really matter as long as you try not to use numbers too often!

(NOTE* If you use numbers, make sure NOT to use them as the first letter since this will mess up the whole variable).

Image


Step 4: Combinations between commands

Combinations between different commands is a really valuable thing when it comes to PHP.
For example; You have several variables, you made sure every variable had t's own value/information, and now you want to print the information from the variable out on the webpage. How is this possible?? Well, here's the solution!

Image

$variable = Variable EX // This means that the variable called "$variable" contains the information: Variable EX.

$something = George // This means that the variable called "$something" contains the information: Goerge.

echo "Insert text here" = This is the command we use for printing out our text onto the webpage.

echo "This is a $variable. And this guy is called $something." = echo tells us that something will be printed onto the webpage. The text inside the quotes " " will be printed out. When adding variables to echo we tell the browser that we want to show the variables correct information. By doing this you can have long long sentences and then convert it to a variable by using the "$variable =" in front.

Example; $variable = this is a long long sentence created to show you guys how a variable can contain information. No matter how long it is. Blah blah blah!!!;

(NOTE* Always make sure to END your codelines with a semi-colon ";" or else the scripts won't work).

Step 5: Scripting - What to keep in mind

When scripting with PHP you need to keep in mind that it won't work out perfectly the first time. You can make so many combinations, so many commands and alot of different variable settings which makes the whole language a pain sometimes. Always make sure to check your code right after you've written it down, instead of going "I'm gonna make 300 lines of code and THEN check if it works!" - Cause' that will only cause more pain!

Another thing to keep in mind when using PHP is to always make your very own reference library and comment every code you make!
For example;

Image

As you can see, I've commented on everything I made! This helps me remember what the particular code does, how I can use it in the future, what the different combinations mean and how to combine different commands with each other.

A typical example of what a Reference Library can look like;

$variable;
#This is a variable. You use variables to store valuable information.

echo "text text text";
#This is the echo command. You use the echo command to print out text or information of some sort to the webpage.

(NOTE* The reference libraries are personal. You only write it as it fits for you. Sure, you can share it with others, but the build of it will be made on a personal basis which means; No one will write their reference libraries like you do).

When doing this you'll learn more, it will stick btter to your mind and perhaps the best part with this is: You can go back and check if you can find a solution to a problem you've had before.

(NOTE* Always save codes/scripts you have written on webpages which solved a problem within the complete PHP-script. You will find this particual script very valuable in the future if it saved you once before).

Another thing to keep in mind is the fact that PHP is not shown when you check the base on a webpage. If you visit google for example, and right lick - show base-code (or whatever it now says in english). You'll be surprised since the PHP used on google have been converted to HTML.

(NOTE* No you can NOT use HTML tags instead of PHP. HTML doesn't have the correct commands to create and do the same things as PHP).


Step 6: Finish - The results

Now, our webpage is complete, for now!
If you have written the same things within your own PHP script as I have, then you will have a webpage with this text on it:
"This is a Variable EX. And this guy is called George.
3 * 4 = 12"

That means, you have now learned the basics of using basic commands, combinations between commands and variables in PHP. Congratulations! Although, this is far from even near completion when it comes to a webpage. A webpage, as many of you may know, concists of many many many lines of code. Especially when it's PHP!

Download Link to the .php file I wrote for this tutorial:
http://dl.dropbox.com/u/3476730/Webb/PHP/PHP_tut.php
Save it, store it, use it!


Thank you for reading this PHP-tutorial!
Leave a comment about what you think!
Regards, DJM aka Sheldin!

DeviantArt Profile
http://sheldiner.deviantart.com/

Youtube (Tutorials/Gaming)
http://www.youtube.com/SheldinLP
User avatar
djm
Pro
Pro
 
Posts: 478
Joined: December 11th, 2009, 4:04 pm
Location: Sweden

Re: PHP Tutorial

Postby 3LeggedDog » October 3rd, 2010, 5:37 am

Too lazy for the tutorial tab - rofl; I just woke up. That's too much. lol.
(I can't stop laughing.....thanks for the tutorial, djm :clap: )

(Edit) Looks good. (We were just talking about that last night - didn't take you long! ;) ). I gotta get something to eat, then I'll do the tutorial. :)

Where do I get the editor; all I found on the web was WAMPServer 2?
User avatar
3LeggedDog
Contributor
Contributor
 
Posts: 145
Joined: June 13th, 2010, 1:49 pm

Re: PHP Tutorial

Postby djm » October 3rd, 2010, 10:04 am

Haha! Well I promised you I would add it this morning (it was late night for me when we had the discussion). :)
And that joke, "for those lazy ones", was kind of a mirror image of myself sometimes.. I have those awful moments sometimes where I'm just being too darn lazy to click on the tutorials tab and instead I do something else.

The server software is called WAMP and it doesn't really matter which version of it it is, but I'd prefer you use the newest one.
The software for programming the PHP doesn't matter. I mean, you can code it with Notepad if you'd like. But I prefer softwares which put colors on the codes, like the one I'm using (Smultron - a swedish made web-development tool. I don't know if there are any english versions of it, but I think so). You can also go with Dreamweaver if you'd like. As I said, it doesn't really matter, as long as the software supports .html and .php.

(EDIT)
WampServer: http://www.wampserver.com/en/download.php
WAMP5: http://www.soft32.com/download_125296.html
To be honest I have no clue which one is the "best" one of these two, but they do the same stuff; They host a local server. The options for MAMP (the mac version of WAMP) were self-made so to speak. I didn't have to edit anything within the options tab. On WAMP it should be the same drill, but I have no clue really since I haven't used this on Windows yet.


(EDIT 2)
Since WAMP seems to be "out-dated" I've decided to check this one out instead: http://www.apachefriends.org/en/xampp-windows.html It's the same as WAMP but it's called XAMPP and according to other Win users it seems to be the better choice right now. It's the same drill as for Mac; Download, extract, Install and Start. No configuration needed.
Within the package you get MySQL, PHP, Perl and Apache (which is the server).
Regards, DJM aka Sheldin!

DeviantArt Profile
http://sheldiner.deviantart.com/

Youtube (Tutorials/Gaming)
http://www.youtube.com/SheldinLP
User avatar
djm
Pro
Pro
 
Posts: 478
Joined: December 11th, 2009, 4:04 pm
Location: Sweden

Re: PHP Tutorial

Postby 3LeggedDog » October 3rd, 2010, 10:17 am

Ok. Thnx. :) (I'll probably get the download(s) tonight, and go over the tut. again tom. evening after work.
User avatar
3LeggedDog
Contributor
Contributor
 
Posts: 145
Joined: June 13th, 2010, 1:49 pm

Re: PHP Tutorial

Postby djm » October 3rd, 2010, 10:25 am

No problems!
I'll look up a stable, fully confirmed, local hosting software for Windows just in case WAMP and XAMPP doesn't work out for you. ^^
Regards, DJM aka Sheldin!

DeviantArt Profile
http://sheldiner.deviantart.com/

Youtube (Tutorials/Gaming)
http://www.youtube.com/SheldinLP
User avatar
djm
Pro
Pro
 
Posts: 478
Joined: December 11th, 2009, 4:04 pm
Location: Sweden

Re: PHP Tutorial

Postby themitchel0 » October 13th, 2010, 5:29 pm

wait so what is the differences of xampp and wapm5/wampserver?
themitchel0
Pro
Pro
 
Posts: 365
Joined: June 15th, 2010, 8:31 am

Re: PHP Tutorial

Postby SPARTAN-001 » October 13th, 2010, 5:35 pm

XAMPP appears to be more stable and up to date. I haven't tried WAMP though, but I can confirm that XAMPP works.
//SPARTAN
Image
Practice makes perfect and nothing is perfect, so why practice? -brektzar
User avatar
SPARTAN-001
Legend
Legend
 
Posts: 1106
Joined: November 5th, 2008, 4:23 pm

Re: PHP Tutorial

Postby themitchel0 » October 14th, 2010, 3:14 am

so how do i get xampp to work? ive downloaded and installed it, so where do i program php now?
themitchel0
Pro
Pro
 
Posts: 365
Joined: June 15th, 2010, 8:31 am

Re: PHP Tutorial

Postby SPARTAN-001 » October 14th, 2010, 4:04 am

You write the PHP in a different editor, and then put it in the XAMPP folder.
//SPARTAN
Image
Practice makes perfect and nothing is perfect, so why practice? -brektzar
User avatar
SPARTAN-001
Legend
Legend
 
Posts: 1106
Joined: November 5th, 2008, 4:23 pm

Re: PHP Tutorial

Postby djm » October 14th, 2010, 11:16 am

themitchel0 - if you READ the tutorial step by step you'll actually SEE where to do what and how to do it! -.-'
Regards, DJM aka Sheldin!

DeviantArt Profile
http://sheldiner.deviantart.com/

Youtube (Tutorials/Gaming)
http://www.youtube.com/SheldinLP
User avatar
djm
Pro
Pro
 
Posts: 478
Joined: December 11th, 2009, 4:04 pm
Location: Sweden
Next
Return to Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests

cron