|
|
#1 (permalink) |
|
GotGames Moderator
|
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 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.. |
|
|
|
|
|
|
|
#2 (permalink) |
|
Pro Member
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
|
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. - |
|
|
|
|
|
#3 (permalink) | |
|
GotGames Moderator
|
Quote:
![]() Actually, <?CHEMISBAD also works... keep it on the hush hush though.
|
|
|
|
|
|
|
#4 (permalink) |
|
Honorary Member
Join Date: Jun 2006
Location: Sydney NSW
Posts: 1,784
Rep Power: 4
|
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); ?> |
|
|
|
|
|
#5 (permalink) | |
|
GotGames Moderator
|
Quote:
I just think getting into good habits of writing code is helpful and prevents messy and confusing code. |
|
|
|
|
|
|
#7 (permalink) |
|
Contributing Member
Join Date: Jun 2006
Posts: 607
Rep Power: 3
|
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. |
|
|
|
|
|
#8 (permalink) |
|
Monster Member
Join Date: Aug 2006
Location: Melbourne
Age: 19
Posts: 3,406
Rep Power: 6
|
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
|
|
|
|
|
|
#9 (permalink) | |
|
GotGames Moderator
|
Quote:
Edit* Thanks lumi. If you have any spare time you should make some photoshop tutorials.
|
|
|
|
|
|
|
#14 (permalink) |
|
Member
|
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 . '.'; Code:
$var = 'orange'; echo "The fruit cup is $var.";
__________________
"I still say a church steeple with a lightning rod on top shows a lack of confidence" ~ Doug McLeod |
|
|
|
|
|
#15 (permalink) | |
|
GotGames Moderator
|
Quote:
|
|
|
|
|
|
|
#19 ( |






+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
) onto the next one now