2 Replies - 2995 Views - Last Post: 03 January 2011 - 08:58 AM Rate Topic: -----

#1 KingScar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-January 11

Full PhP Tutorial

Posted 03 January 2011 - 05:28 AM

Hey everybody,
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.



FAQ



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.


Code Key


<?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.




Starting PhP


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.

Variables

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


Is This A Good Question/Topic? 0
  • +

Replies To: Full PhP Tutorial

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,612
  • Joined: 23-August 08

Re: Full PhP Tutorial

Posted 03 January 2011 - 05:43 AM

If you wish to submit a tutorial, then do so HERE, where it will be reviewed and approved after review.

And it's NOT PhP, it's PHP.
Was This Post Helpful? 2
  • +
  • -

#3 JamesRozee  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 26
  • Joined: 01-January 11

Re: Full PhP Tutorial

Posted 03 January 2011 - 08:58 AM

View PostJackOfAllTrades, on 03 January 2011 - 11:43 AM, said:

If you wish to submit a tutorial, then do so HERE, where it will be reviewed and approved after review.

And it's NOT PhP, it's PHP.


For any beginner wanting to learn PHP would struggle following this tutorial.

Not trying to shoot you down but how would they go making a PHP file if they dont even know what extension to use!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1