I wrote this a long time ago, and I figure I'd put it out here for everyone to peruse. It's an incomplete tutorial, but has some pretty in-depth, useful info (at least I hope it does). If you all want to make this a little more comprehensive, feel free to post additions and I'll edit them in. I'm more curious about everyone's thoughts, and whether this even seems like it's any good.
I'd really like to add a few sections in the near future, espcially:
[LIST]
[*]Foreach loops
[*]Conditional statements
[/LIST]And probably a few more things I can't think off from the top of my head. So without furthur ado, a wall of text:
-------------------------------------------------------
[B][U]What is PHP?
[/U][/B]PHP is a server-side coding language. It's full name is Hypertext Preprocessing, and it does exactly what it sounds like. Any code is executed before the webpage is sent to the client. This is why you can't extract PHP code directly from a webpage, even if you're accessing a PHP file.
[B][U]How do I even put PHP in a webpage?
[/U][/B]PHP has its own tags. Regardless of whether you include your PHP code in an HTML file or as its own PHP file, you still need the tags. The tags are:
[php]<?php
?>[/php]You can then include your PHP code within those tags.
[U][B]This is confusing! Isn't there a reference or something?
[/B][/U]Absolutely! PHP has a fantastic reference manual. You can find it [URL="http://php.net/manual/en/index.php"]here[/URL]. It has a function look up and within a few key strokes you can usually find the function category you're looking for. It not only includes examples of usage, but also includes information about parameters and discussion by users. Many of the users are unbelievably helpful, by talking about when it is or isn't a good time to use a particular function, and alternatives a coder can consider. All in all, it's HIGHLY recommended you bookmark the manual if you ever really want to take your coding to any sort of next step. In fact, without it, I'd never even know about any of the functions I often use in my code.
[B][U]What tools should I have in order to code?
[/U][/B]You're going to want a tool with code highlighting. [URL="http://notepad-plus-plus.org/"]Notepad++[/URL] works wondrously, is free, and is useful for other languages beyond PHP. In fact, it might be one of the most useful programs to any aspiring coder regardless of the type of code they're working with.
[B][U]Do you use it?
[/U][/B]I do not use Notepad++, although for a while I did. I use a program called PhpED. It's an IDE, or Integrated Development Environment, which basically means is has every tool I could possibly need to code. It has a popup function manual which tells me what each parameter of a function will do as I code, and it also has a built-in local server. The latter feature is the main reason I use it. Because PHP is serverside code, you actually need to put it on an Apache server and then connect to it to see the output. The Apache server parses the PHP code, and outputs the result. You may be able to find a free program that does this, I'm not sure. However, if you aren't able to, you'll need a server in order to check your code. There are plenty of websites that will give you some free space, and PHP code is pretty small, so you shouldn't have a problem going over your memory limit.
[B][U]Enough talk, lets actually start some coding!
[/U][/B]Alright, alright. Lets quickly talk about the basic components to any piece of code. The first is an unbreakable rule, the rest are actual pieces of code. Just remember the first thing, it's probably the most important piece of proper code. If you don't follow it, anything you ever code will [B][U]NEVER[/U][/B] work:[B]
[U]Always[/U] end a statement with a semicolon ";".[/B] There are some cases where they aren't mandatory, but even if you come across a case where this is true, it will never break the code. As a rule of thumb, it's always good to end a statement with a semicolon.
[U][B]Variables:
[/B][/U]A variable is basically an identifier for something. It works exactly like a variable in any other language. Whenever a variable is declared, you MUST use a dollar sign before it "$". The best way to really discuss them is to give a quick example:
[php]<?php
$variable = "1";
print($variable);
?>[/php]
You'll see that the first thing we've done is assigned the variable a value. In this case, the variable is technically a string, although we can still do mathematical processes to it. If you said "print($variable+1)" it would print 2 instead of 1, because you've added 1 to it, although you'll note we haven't enclosed the 1 in quotation marks, the PHP is still able to understand what you're saying. This is not always true, as we'll see in arrays, but it's important to understand the flexibility of the language. Finally, the "print" code actually prints the variable in a readable format. This function does not ALWAYS work for variables, as arrays do break it, but it works for variables that hold a single value.
[U][B]
Arrays:
[/B][/U]Arrays are, perhaps, even more useful than variables. Like variables, arrays store values, but unlike variables which can only store a single declarable value, arrays are able to store an infinite number of declarable values. As an example, lets make a simple array:
[php]<?php
$array = array(
1 => "One",
2 => "Two"
);
print($array[1]);
print($array[2]);
?>[/php]
Ok lets break this down, there's a lot going on here. First of all, you can clearly see we've assigned the variable "array" to the value of an array. For all intents and purposes, even though $array is technically a variable, it identifies an array, so we'll call $array an array. Moving on, you'll see that arrays are notated pretty differently than variables. Firstly, lets break down the way an array works. Arrays assign values to keys. Lets look at the way our array is set up. The first thing we've done is assigned the [U]value[/U] "One" (which in this case is the string One) to the [U]key[/U] 1 (the numeric 1). By default, an array will automatically assign values to numerically increasing keys. Basically, if you didn't actually declare the keys, as we have here with the "=>" symbol, you would still have the same keys, since the array function, by default, does just what we've done here. You'll also note that within the array() function, we didn't need to use semicolons, since semicolons are only used at the END of statements, and to use them within the function would break the statement. You will see, however, that we did use it at the end of the function, since you've finished the entire statement at that point. In any array, you do need to break up each value with a comma, except the last one, as you can see here. Finally, to call a value that's stored within the array, we need to call the key in addition to the variable of the array itself. You'll see that in each of the prints, in order to call the value, we needed to further identify what particular value we want to call by its key "$array[1]" and "$array[2]". If your keys are strings, for instance, than you need to enclose them within quotation marks, or, preferably, apostrophes " ' ".
[U][B]
Functions:
[/B][/U]Functions are the backbone of PHP coding. A good analogy for the relationship between functions and arrays and variables is that arrays and variables [B]say[/B] something, and functions [B]do[/B] to or with what was said. You need both in order to really have your code do anything. In fact, in the examples about, you'll actually see some functions in use. For instance, whenever we've called "print()", that's a function as we've been outputting what was said. Way above, you'll see a link I posted, the PHP reference manual. It's incredibly useful, and it includes a reference for every function PHP includes by default, and many functions that have been added by third parties. PHP is open source, so if you want to do something, but it's not supported by default, chances are it's been coded by someone else, either as a class or as a separate library entirely.
---------------------------------------------------------------------
I apologize for the any illegibility it might have. I've largely copied and pasted this, but tried to make it as readable as possibly in the little time I've had.
I understand you wrote this a long time ago, and it doesn't attempt to be an all-encompassing guide, but I wouldn't recommend others follow this tutorial.
[B]1.[/B] It's confusing as to the expected knowledge level.
[B]2. [/B]The writing is extremely circular and all over the place; very poor overall.
[B]3.[/B] You're teaching mostly language-agnostic concepts, and in a counter-intuitive manner - very much in the style of most other PHP beginner tutorials, there's very little care that the reader understand what's going on under the hood, or how these different elements are used together. In my opinion this is unacceptable for any developer, and given the amount of shit PHP has hidden under the mattress, I would never recommend it as a first language.
[B]4.[/B] It's filled with factual errors and inconsistencies, and shows a poor understanding on your behalf of the things you're trying to teach.
For something like this I'd rather see a tutorial guiding the user through the process of setting up a local development stack (with brief explanations of the other players, without ignoring the importance of the web server, the [B]HTTP protocol[/B][this is ignored every.single.fucking.time], and the underlying operating system), writing a small "hello world" script, integrating that in a web-development scenario and then building on that with clearly sectioned and documented goals, and the steps towards fulfilling them. Something in the style of the common "create a blog in 5 minutes!" tutorials you see bundled with popular frameworks would be enough.
Sorry if I sound like a blubbering fool, it's late and I'm going to hit the sack.
Nah no problem. I totally understand what you're getting at here, and I completely agree. But like I said, this is only here as a jumping off point. If someone wants to edit this, you're totally allowed. Or we can just let this die. That's fine too. :smile:
Oh and as an addendum: my knowledge is entirely self-taught, so I don't pretend to have a serious grasp on the specific terminology. I just code. I guess this is kind of a serious fault, but when I wrote this, I felt even my less-than-adequate knowledge (and at that time, far less than adequate) could at least give a little background knowledge. But anyway, I'll just let this mull a little.
Not a good tutorial. It is clear that you have some misunderstandings to how the language works, and the terms you use is misleading too. [quote] You'll see that the first thing we've done is assigned the variable a value. In this case, the variable is technically a string, although we can still do mathematical processes to it. If you said "print($variable+1)" it would print 2 instead of 1, because you've added 1 to it, although you'll note we haven't enclosed the 1 in quotation marks, the PHP is still able to understand what you're saying. [/quote] Using strings for numeric variables is just wrong and puts more work on the interpreter (As it has to convert your string to a numeric and THEN add the numbers) You should use var_dump instead of print, that will give users a better idea of how the different datatypes work. Array is not a function, but a language construct You fail to mention PECL and PEAR as ways to extend the functionality of PHP. No hello world ? all in all theres not much tutorial here, and its very bad structured..
I've been wanting to get into Web Design/Development for quite a while now, but I'm not sure exactly how to go about doing so. All I need to learn is HTML, then CSS, from what I'm ready?
Also, I'm looking at domain names and I don't know which server/host would be best for me to buy. I don't know the benefits on having a Windows server or a Linux server distribution, nor what site to go through.
[QUOTE=Crastopher;31065432]I've been wanting to get into Web Design/Development for quite a while now, but I'm not sure exactly how to go about doing so. All I need to learn is HTML, then CSS, from what I'm ready?
Also, I'm looking at domain names and I don't know which server/host would be best for me to buy. I don't know the benefits on having a Windows server or a Linux server distribution, nor what site to go through.[/QUOTE]
If you're only learning XAMPP would be enough. If you're wanting to do any back end server side work you'll want to learn more than just HTML and CSS.
Where is the PDO tutorial?
Perhaps someone ought to close this and save everyone some effort.
I more or less posted this because it existed. If you're learning PHP, one of the the best ways, at least for me, is to look at some existing code, and pick apart each function by referencing it to the PHP manual.
But as has been said--this isn't a particularly useful guide. So I'd appreciate it if someone would possibly close this to avoid causing confusion for people who are just starting out with coding..
I'd like to mention that PHP has other very uncommon uses like for programing applications for Windows.
Also, where did the devs get that extra "p" from? Shouldn't the language really by HP?
[QUOTE=toaster468;31081566]Also, where did the devs get that extra "p" from? Shouldn't the language really by HP?[/QUOTE]
No. PHP is a recursive acronym which stands for "PHP: Hypertext Preprocessor", like WINE, which stands for "Wine Is Not an Emulator".
This is rather helpful, thanks.
Never needed to properly use PHP, always wanted to learn. Might give it a go :)
Not that bad of a tutorial, everyone's gonna have their own opinions on what makes a tutorial "good" and the best way to teach new people. When I was new to programming I wanted to jump write in and write code that actually did something. That's the best way to learn for me. You have plenty of time to learn the technical details later..that stuff is boring to the average noob in my opinion.
[QUOTE=cas97;31081957]No. PHP is a recursive acronym which stands for "PHP: Hypertext Preprocessor", like WINE, which stands for "Wine Is Not an Emulator".[/QUOTE]
PHP stands for Personal Homepage though doesn't it? So it's personal homepage hypertext preprocessor if you're feeling fruity.
[QUOTE=Sh33p;31099986]PHP stands for Personal Homepage though doesn't it? So it's personal homepage hypertext preprocessor if you're feeling fruity.[/QUOTE]
Nope, it's a recursive acronym: PHP --> PHP Hypertext Preprocessor. Sort of like WINE ("WINE Is Not an Emulator").
[editline]14th July 2011[/editline]
[QUOTE=cas97;31081957]No. PHP is a recursive acronym which stands for "PHP: Hypertext Preprocessor", like WINE, which stands for "Wine Is Not an Emulator".[/QUOTE]
Oh oops. Anyone got the time?
[QUOTE=StinkyJoe;31100091]Nope, it's a recursive acronym: PHP --> PHP Hypertext Preprocessor. Sort of like WINE ("WINE Is Not an Emulator").[/QUOTE]
Or GNU — GNU's Not Unix :eng101:
I does I PHP?
[QUOTE=TeratybeS;31100718]Or GNU — GNU's Not Unix :eng101:[/QUOTE]
Or LAME - LAME Ain't an Mp3 Encoder.