Jump to content


Photo
- - - - -

Learning the Basics of PHP


  • Please log in to reply
3 replies to this topic

#1 albinoAZN

albinoAZN

    Albinos Are Extinct!!!

  • Members
  • PipPipPipPip
  • 1,139 posts
  • Gender:Male
  • Location:Mississippi, USA

Posted 19 June 2006 - 01:32 PM

PHP Introduction:

PHP is a computer language for the world wide web. You may think want PHP
stands, but actually it does not stand for anything
unlike many other computer languages.

PHP Editors:

There are many php editors out on the market, some free, some paid. A very
popular editor is Dreamweaver, but you have to buy it first. I use
PHP Eclipse, which is a plugin for Eclipse, which is an Open Source software.
But for this tutorial all you will need is notepad.

How-To open a PHP document:

To open a php document or to start php all you have to type is:

<?php

Or:

<?

To close a PHP document is to type:

?>

In between these 2 tags you can then execute your PHP code.

Print text to the browser:

To print some text to the browser you have to do the following:

<?php

echo 'Hello World'; //This will print 'Hello World' to the browser.

?>

Now the echo command is telling PHP to print the following text to the browser.
Notice how I have a ';' at the end
of the end. If you do not add this, then you will not be able to execute any
more PHP code or you will get an error.
This is telling php that this line of code is finished, and you then want to go
onto the next line of code in your document.

Saving a PHP Document:

When saving a php document, you want the extension to be '.php' eg:
'my_first_app.php'
You will then need a server that supports PHP to view your the document you
just created.

Comments:

Comments are so you can add a comment in your php document.

If you type '//' (without quotes) this will then comment anything you type on
the current line, like what i have done in the example above.
If you wish to comment more than 1 line, then you will have to type: '/*' to
open it, and '*/' to end the comment.

Example:

<?php

/* Start the comment

This is a multiline comment.

More text.

End the comment here */

echo 'Comment Finished'; //Comment that will only work on the current line.

?>

Variables:

Variables is something that will hold data for you. The later you can use the
variable later in your code.

Example:

<?php

$var = 'This is a variable'; //Store 'This is a variable' in the varaible
called: '$var'

echo $var; //This will print what ever is stored in $var.

?>

If Else Statements:

If else statments are one of the most important features in PHP aswell as a lot
of languages. It allows for conditional execution of code.

Example:

<?php

$num1 = '1'; //Store some data
$num2 = '2'; //Store some more data

if ($num1 == $num2) //Make sure you type '==', this will then check if $num1 =
$num2. If you just put '=', Then $num1 will equal $num2
{ //Start the code to execute
echo 'Success';
} //End the code that you executes

else //If $num1 does not equal $num2 then we want the execute the following
code:
{
echo 'Failed';
}

?>

written by my good friend ben to go on my website, But I shut down on submitting tutorials when he gave it to me.

#2 coldkill

coldkill

    Young Padawan

  • Members
  • Pip
  • 11 posts
  • Gender:Male
  • Location:Devon, United Kingdom

Posted 19 June 2006 - 05:57 PM

Nice into to PHP. However, PHP stands for Hypertext PreProcessor (HPP really instead of PHP but meh). It used to be the creaters initials I believe.

<?PHP
Is a better way of starting off PHP code because some early engines may get confused and not start the script dunno why but better to be safe than sorry.

You can also use the
#
symbol to start single line comments.

Variables can also be intialised by using the function var then the name with a $ sign the static data ( you can't declare it with another variable.
Example
// Works
var $var = "This is a variable!";

// doesn't work
var $var = $another_var;

Cold

#3 Minh88BT

Minh88BT

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 09 July 2006 - 01:02 PM

^^ i still dont get it :)

#4 Indigo

Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 11 July 2006 - 09:03 AM

Really, really basic, but it might come in handy for somebody. You should've included something about loops and use of "else if", then it would've been better.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users