Old 02-05-2007   #1 (permalink)
chX
GotGames Moderator
 
chX's Avatar
 
Join Date: Jan 2007
Location: Adelaide
Age: 17
Posts: 3,760
Rep Power: 5
Send a message via MSN to chX
Default Chaos' PHP Tutorial - Part 1: An Introduction.

Chaos' PHP Tutorial - Part 1: An Introduction.

This is the first part of the PHP tutorials I am planning on making. It is simply an introduction into what PHP is, what it can do and a few simple commands. The tutorials I will be creating after this will go into more detail regarding various commands, functions, variables and possibly Object-Oriented Programming.

What is PHP? A brief history
PHP is a recursive acronym for PHP:Hypertext Preprocessor. It was originally written by a programmer called Rasmus Lerdorf in 1994, as a set of CGI binaries (used in C) to replace Perl scripts that he had been using to run his personal homepage. It grew and developed from there, having the parser rewritten in 1997 and modifications made. In 1998 PHP 3 was officially released. The PHP Group took over from there, releasing PHP 4 in May 2000 on the Zend Engine. PHP 5 was released in July, 2004. PHP 5 came with many new features, the most prominent being support for Object-Oriented Programming and better support for MySQL. Object-Oriented Programming (OOP henceforth) is still included in PHP 4; however, it is limited in features and flexibility.

Source: Wikipedia.

What does PHP do?
PHP is a server-side scripting language. This means that it is parsed on the server, rather than on the client's PC. This differs to HTML and JavaScript as they are both client-side scripts and parsed on the client's PC. This provides more security and also prevents anyone from viewing the PHP source code without having direct access to the files. This is because the PHP is parsed before anything else on the page. PHP is used to create dynamic websites with an array of features that could not be supported or run on regular HTML. This forum for example, is run on PHP with a database of some form (usually MySQL)
to store and update content.

Okay, enough with the history... what are some commands?
As I stated earlier, PHP is parsed before anything else on a website. The server must first be running PHP before it will recognise any code, otherwise it simply prints it out as regular text. Any PHP code needs to be between an opening delimiter (<?PHP for long-hand or <? for short-hand) and closing delimiter (?>) -- the server will then parse anything which is inbetween.

One of the most commonly used commands in PHP is called "echo" or its sister, "print." These commands both spit out some text in the user's browser (print has some nifty functions which echo doesn't.) The syntax for these commands is: echo "some text goes here"; and print ("some text goes here"); print will also work without using the parentheses. A basic example of this is the following:

PHP Code:
<?PHP

echo "Hello world!";

?>
You can also display text inbetween HTML code. For example:

PHP Code:
<HTML>
<HEAD>
</HEAD>
<BODY>
<p>This is a line of text which is displayed with simple HTML.</p>
<?PHP
echo "This is a line of text which is being parsed through PHP and displayed exactly the same as the above text.";
?>
</BODY>
</HTML>
You may have noticed a semi-colon ( ; ) at the end of most lines. This indicated a termination and tells the server that you have terminated that line of code.
It is very important you learn to use these, as missing one semi-colon will ruin your entire script until you fix it.

There are some very nifty things you can do using PHP and I'll be going into them next time!

Well, that concludes part 1 of the PHP tutorial. I hope you enjoyed it and I'll be creating another tutorial every once in a while, so stay tuned. If you have any questions/comments about the tutorial feel free to PM me or even respond in the thread.

--Chaos.

Last edited by chX; 03-05-2007 at 03:57 PM..
chX is offline   Reply With Quote
Old 02-05-2007   #2 (permalink)
Pro Member
 
chemicalNova's Avatar
 
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
Default

Get to sessions dammit!

Nicely written.

I never knew <?PHP was the only other option. I thought <?YOURMOTHER would work also.. does it not?

Anywho.. well done

chem
__________________
There are no stupid questions... but there are alot of inquisitive idiots.
-
chemicalNova is offline   Reply With Quote
Old 02-05-2007   #3 (permalink)
chX
GotGames Moderator
 
chX's Avatar
 
Join Date: Jan 2007
Location: Adelaide
Age: 17
Posts: 3,760
Rep Power: 5
Send a message via MSN to chX
Default

Quote:
Originally Posted by chemicalNova View Post
Get to sessions dammit!

Nicely written.

I never knew <?PHP was the only other option. I thought <?YOURMOTHER would work also.. does it not?

Anywho.. well done

chem
Haha, I figured it would be wise to write up some simple and basic commands/functions before posting sessions/cookies/MySQL as that would confuse everyone who reads it and is unexperienced.

Actually, <?CHEMISBAD also works... keep it on the hush hush though.
chX is offline   Reply With Quote
Old 02-05-2007   #4 (permalink)
Honorary Member
 
doublethink's Avatar
 
Join Date: Jun 2006
Location: Sydney NSW
Posts: 1,784
Rep Power: 4
Default

Quote:
Originally Posted by ChaosX View Post
PHP is a recursive acronym for PHP:Hypertext Preprocessor.
I always thought it stood for "Pre Hypertext Processor" :/ Maybe they switched the name on me when I wasn't looking...

If you have short open tags on, then you can also use

<?= $some_string_here ?>

which is the same as doing

<?php echo($some_string_here); ?>
doublethink is offline   Reply With Quote
Old 02-05-2007   #5 (permalink)
chX
GotGames Moderator
 
chX's Avatar
 
Join Date: Jan 2007
Location: Adelaide
Age: 17
Posts: 3,760
Rep Power: 5
Send a message via MSN to chX
Default

Quote:
Originally Posted by doublethink View Post
I always thought it stood for "Pre Hypertext Processor" :/ Maybe they switched the name on me when I wasn't looking...

If you have short open tags on, then you can also use

<?= $some_string_here ?>

which is the same as doing

<?php echo($some_string_here); ?>
Yeah. I prefer using the long-hand version of the delimiters for the reason that some servers don't have short-hand enabled. If you're making any sort of open-sourced software that can be used on many different servers, you need to ensure that it will actually work on all of the servers.

I just think getting into good habits of writing code is helpful and prevents messy and confusing code.
chX is offline   Reply With Quote
Old 02-05-2007   #6 (permalink)
Monster Member
 
Join Date: Jan 2007
Location: Brisbane, Australia
Age: 19
Posts: 3,500
Rep Power: 6
Default

Haha - you should put the semicolon part in bold - i've spent countless minutes looking for one semicolon that's missing
__________________
Jayson
Jayso is offline   Reply With Quote
Old 02-05-2007   #7 (permalink)
Contributing Member
 
Join Date: Jun 2006
Posts: 607
Rep Power: 3
Default

PHP can also support (bad idea) asp style which is
<%
now <? is a bad idea, use <?php as support for <? can be turned off
and please. never use <?= again, reason above.
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this into your signature.
Khaless is offline   Reply With Quote
Old 02-05-2007   #8 (permalink)
Monster Member
 
lumi's Avatar
 
Join Date: Aug 2006
Location: Melbourne
Age: 19
Posts: 3,406
Rep Power: 6
Default

Not that I'm that interested in learning PHP but I think this is great and I will read it for some extra epeen +1 for your efforts it's great... when I've read it (sometime tomorrow) I will post and tell you what i thought of it from a noob programmer perspective
__________________

Play .OGG
lumi is offline   Reply With Quote
Old 02-05-2007   #9 (permalink)
chX
GotGames Moderator
 
chX's Avatar
 
Join Date: Jan 2007
Location: Adelaide
Age: 17
Posts: 3,760
Rep Power: 5
Send a message via MSN to chX
Default

Quote:
Originally Posted by Khaless View Post
PHP can also support (bad idea) asp style which is
<%
now <? is a bad idea, use <?php as support for <? can be turned off
and please. never use <?= again, reason above.
I've never even seen the use of <?= so I have no idea what it does. In my opinion <?php is the way to go.

Edit* Thanks lumi. If you have any spare time you should make some photoshop tutorials.
chX is offline   Reply With Quote
Old 02-05-2007   #10 (permalink)
Monster Member
 
lumi's Avatar
 
Join Date: Aug 2006
Location: Melbourne
Age: 19
Posts: 3,406
Rep Power: 6
Default

Quote:
Originally Posted by ChaosX View Post
Edit* Thanks lumi. If you have any spare time you should make some photoshop tutorials.
I've already taken that into consideration and I will do it for sure when I get the time, any specific topic you want me to cover? of course I will do one that covers the basics.
__________________

Play .OGG
lumi is offline   Reply With Quote
Old 02-05-2007   #11 (permalink)
chX
GotGames Moderator
 
chX's Avatar
 
Join Date: Jan 2007
Location: Adelaide
Age: 17
Posts: 3,760
Rep Power: 5
Send a message via MSN to chX
Default

Quote:
Originally Posted by lumi View Post
I've already taken that into consideration and I will do it for sure when I get the time, any specific topic you want me to cover? of course I will do one that covers the basics.
Well I'm fairly experienced with Photoshop, I can do a lot of the basic stuff and effects. Perhaps just think of something you really enjoy to do with photoshop and are good at and make a tutorial on that. You seem fairly good with logo making and etc.
chX is offline   Reply With Quote
Old 03-05-2007   #12 (permalink)
Monster Member
 
lumi's Avatar
 
Join Date: Aug 2006
Location: Melbourne
Age: 19
Posts: 3,406
Rep Power: 6
Default

Ok I've read this section and even from a noob programmers point of view (me) that was all pretty basic (in a good way ) onto the next one now
__________________

Play .OGG
lumi is offline   Reply With Quote
Old 03-05-2007   #13 (permalink)
chX
GotGames Moderator
 
chX's Avatar
 
Join Date: Jan 2007
Location: Adelaide
Age: 17
Posts: 3,760
Rep Power: 5
Send a message via MSN to chX
Default

Quote:
Originally Posted by lumi View Post
Ok I've read this section and even from a noob programmers point of view (me) that was all pretty basic (in a good way ) onto the next one now
Excellent. So you understood is pretty well?
chX is offline   Reply With Quote
Old 24-05-2007   #14 (permalink)
Member
 
Depodra's Avatar
 
Join Date: Jun 2006
Location: Toowoomba, QLD, AU.
Posts: 116
Rep Power: 3
Send a message via MSN to Depodra
Default

As a side note, to save some time (nonoseconds) you should pretty much avoid all double quotes (") as much as possible (unless of course you're creating a new line etc with \n or carriage returns) as anything within the double quotation marks will be parsed through the PHP engine to look for variables, instead of being treated as a plain/text string.

E.g:

Code:
$var = 'orange';
echo 'The fruit cup is ' . $var . '.';
as apposed to:
Code:
$var = 'orange';
echo "The fruit cup is $var.";
Yes, it's minuscule, but yeah... *slowly nods*
__________________
"I still say a church steeple with a lightning rod on top shows a lack of confidence" ~ Doug McLeod
Depodra is offline   Reply With Quote
Old 24-05-2007   #15 (permalink)
chX
GotGames Moderator
 
chX's Avatar
 
Join Date: Jan 2007
Location: Adelaide
Age: 17
Posts: 3,760
Rep Power: 5
Send a message via MSN to chX
Default

Quote:
Originally Posted by Depodra View Post
As a side note, to save some time (nonoseconds) you should pretty much avoid all double quotes (") as much as possible (unless of course you're creating a new line etc with \n or carriage returns) as anything within the double quotation marks will be parsed through the PHP engine to look for variables, instead of being treated as a plain/text string.

E.g:

Code:
$var = 'orange';
echo 'The fruit cup is ' . $var . '.';
as apposed to:
Code:
$var = 'orange';
echo "The fruit cup is $var.";
Yes, it's minuscule, but yeah... *slowly nods*
Thanks for the info. Those extra nanoseconds that it takes by using the double quotes allows me to reach into their pockets and take their wallet.

chX is offline   Reply With Quote
Old 24-05-2007   #16 (permalink)
Member
 
Depodra's Avatar
 
Join Date: Jun 2006
Location: Toowoomba, QLD, AU.
Posts: 116
Rep Power: 3
Send a message via MSN to Depodra
Default

Quote:
Originally Posted by ChaosX View Post
Thanks for the info. Those extra nanoseconds that it takes by using the double quotes allows me to reach into their pockets and take their wallet.

Hmmm... aren't you the wallet inspector I gave my wallet to the other day..? How's that going, I might need that back soon...
__________________
"I still say a church steeple with a lightning rod on top shows a lack of confidence" ~ Doug McLeod
Depodra is offline   Reply With Quote
Old 24-05-2007   #17 (permalink)
chX
GotGames Moderator
 
chX's Avatar
 
Join Date: Jan 2007
Location: Adelaide
Age: 17
Posts: 3,760
Rep Power: 5
Send a message via MSN to chX
Default

Quote:
Originally Posted by Depodra View Post
Hmmm... aren't you the wallet inspector I gave my wallet to the other day..? How's that going, I might need that back soon...
No... uh... I think you're thinking about a different guy... you see...

I uh... um...

*Runs*
chX is offline   Reply With Quote
Old 24-09-2008   #18 (permalink)
Banned
 
Join Date: Jun 2008
Location: sydney
Posts: 1,573
Rep Power: 0
Default

well d0ne
funkyBUDDHA is offline   Reply With Quote
Old 24-09-2008   #19 (