even though I just joined this site I feel like the best way to start is to do something the community
can benefit from right off the bat which is why I'm creating this fully fledged and in-depth PhP tutorial. It will not be complete in one shot I'll edit and update it often so their will eventually be a tutorial on here that beginners and veterans alike could get some use out of.
What is PhP?
PhP is a Hypertext Preprocessor and it is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel. It may also function as a graphical application. PHP is available as a processor for most modern web servers and as a standalone interpreter on most operating systems and computing platforms.
Who created PhP?
PHP was originally created by Rasmus Lerdorf in 1995 and has been in continuous development ever since. The main implementation of PHP is now produced by the PHP Group and serves as the de facto standard for PHP as there is no formal specification.
How much does PhP cost?
PHP is free software released under the PHP License.
<?php = The opening declaration of a PhP document.
?> = closing a PhP document
/* = start of a comment
*/ = end of a comment
$ = declare a variable.
Side Note:(Don't forget to name your variables properly! variables must start with a letter or underscore. a variable name can only contain alpha-numeric characters (a-z, A-Z, 0-9, and _) and you shouldn't space it either. if you need to separate words use the underscore.)
echo = output text.
print = output text.
if statement = use this statement to execute some code only if a specified condition is true.
if...else statement = use this statement to execute some code if a condition is true and another code if the condition is false.
if else if else statement = use this statement to select one of several blocks of code to be executed.
switch statement = use this statement to select one of many blocks of code to be executed.
while = loops through a block of code while a specified condition is true.
do...while = loops through a block of code once, and then repeats the loop as long as a specified condition is true.
for = loops through a block of code a specified number of times.
foreach = loops through a block of code for each element in an array.
function functionName() = To keep a script from being executed when the page loads, you can put it into a function. This script will only be executed if you 'call' the function.
PhP works along side HTML which is why unless you're writing a specific piece of code you should open your PhP documents with an <html> tag.
Regardless what language you choose to start out in, it always begins with one program. Yes, the infamous "Hello World!" program. Here's how it works:
<html> <head><title></title></head> <body> <?php echo "Hello World!"; ?> </body> </html>
Lets break this down now:
<html> <- tells you it is an html web page.
<head> <- where you put all code that isn't going to show up physically on the web page.
<title> <- name of webpage.
</title> <- closes name.
</head> <- ends the head section of the document.
<body> <- where all code physically effecting the web page goes.
<?php <- tells you PhP is about to be used.
echo "Hello World!"; <- tells your computer to show "Hello World" on screen.
?> <- ends PhP code.
</body> <- ends body section of document.
</html> <- closes the document completely.
You might be wondering why I end the single line of code I had (echo "Hello World!") with a semicolon. Well, that's because in PhP along with almost every other language each line of code needs to end with a semicolon, it tells your computer that the task that line was assigned to do has been done and to kill the line.
Just like in math, variables are used to store values that can be used whenever and wherever. I can hold things like text strings, numbers, or even Arrays (special variables).
each time you create a variable you must use $ to start off, it's how you declare a variable. Like this:
<html> <head><title></title> <body> <?php $hello = "hello"; $world = "world!"; ?> </body> </html>
I've declared two variables with set values in both. Now, if I wanted I could say, "echo $hello;" in my php document and the word "hello" would show up on screen because, it's the value to that variable.
This post has been edited by KingScar: 03 January 2011 - 05:32 AM