DEVTOME.COM HOSTING COSTS HAVE BEGUN TO EXCEED 115$ MONTHLY. THE ADMINISTRATION IS NO LONGER ABLE TO HANDLE THE COST WITHOUT ASSISTANCE DUE TO THE RISING COST. THIS HAS BEEN OCCURRING FOR ALMOST A YEAR, BUT WE HAVE BEEN HANDLING IT FROM OUR OWN POCKETS. HOWEVER, WITH LITERALLY NO DONATIONS FOR THE PAST 2+ YEARS IT HAS DEPLETED THE BUDGET IN SHORT ORDER WITH THE INCREASE IN ACTIVITY ON THE SITE IN THE PAST 6 MONTHS. OUR CPU USAGE HAS BECOME TOO HIGH TO REMAIN ON A REASONABLE COSTING PLAN THAT WE COULD MAINTAIN. IF YOU WOULD LIKE TO SUPPORT THE DEVTOME PROJECT AND KEEP THE SITE UP/ALIVE PLEASE DONATE (EVEN IF ITS A SATOSHI) TO OUR DEVCOIN 1M4PCuMXvpWX6LHPkBEf3LJ2z1boZv4EQa OR OUR BTC WALLET 16eqEcqfw4zHUh2znvMcmRzGVwCn7CJLxR TO ALLOW US TO AFFORD THE HOSTING.

THE DEVCOIN AND DEVTOME PROJECTS ARE BOTH VERY IMPORTANT TO THE COMMUNITY. PLEASE CONTRIBUTE TO ITS FURTHER SUCCESS FOR ANOTHER 5 OR MORE YEARS!

Hello reader!

In this tutorial I will show you the basics about PHP programming on windows.

First you will need

  1. Apache (the core of the webserver)
  2. PHP (a module of Apache we will make PHP programs)
  3. Mysql (there are some SQL servers but I will use Mysql in this tutorial)
  4. Sqlite (similar to Mysql but it's uses 1 file to store the db I use with PDO)

To get these things you can donwload one-by-one or you can donwload an package for all of it:

For all of it in 1 installer:
	-wampsever : 32 bit http://sourceforge.net/projects/wampserver/files/WampServer%202/Wampserver%202.4/Wampserver2.4-x86.exe/download 64 bit http://sourceforge.net/projects/wampserver/files/WampServer%202/Wampserver%202.4/Wampserver2.4-x64.exe/download
	-Xampp : http://www.apachefriends.org/download.php?xampp-win32-1.8.2-3-VC9-installer.exe
	-uniform server (I use this cause it's small and portable): http://sourceforge.net/projects/miniserver/files/Uniform%20Server/ chose your version

We can use and IDE or just notepad for coding but with an IDE it's much easier:

Eclipse PHP: 32 bit http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/helios/R/eclipse-php-helios-win32.zip 64 bit http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/helios/R/eclipse-php-helios-win32-x86_64.zip
Eclipse PDT (addon for any eclipse product like Java IDE): http://download.eclipse.org/tools/pdt/updates/3.2/release add this as program source then install PDT
Netbeans PHP: https://netbeans.org/downloads/start.html?platform=windows&lang=en&option=php

After you selected one of the servers and one of the IDEs and installed it we can start making programs.

Start the server

If you selected one server with installer you can start from the startmenu or from the installdir. On the main console press start to Apache and Mysql.

You first program "Hello World!"

The PHP applications are starting with <?php and ends with ?> thing write betwen this two tag will pre compiled. The browsers only can show you HTML content so it will NEVER compile you PHP code.

<?php
print "Hello world!";
?>

Save this to INSTALLDIR_OF_THE_SERVER/www or /htdocs with .php extension. This will produce this:

Hello world!

Now you have completed your first program. You can use “echo” instead of “print” it will do the same. YOu have to put ”;” to all of the end of the lines. You can make comments with or with .

Variables

In php there are type of variables:

  1. Integer (only number like:0, 54)
  2. Float (numbers with floating point like: 0.50 , 9.959595)
  3. String (texts like: This text)
  4. Array (multiple string in 1 variable)
  5. Boolean (TRUE or FALSE / 1 or 0)
  6. Objects (classes)
  7. NULL (variable without content)

Variables start with “$”.

(you not really have to know all of it cause PHP not require to define variable types like java) But in this program I show you all of it.

<?php
$integer = 1250980;
$float = 0.255;
$string = "This is a string";
$array = array("1. thing", "2. thing");
$null = NULL;
class MyClass{
public function print_thing(){
print "thing";
}
}
$class = new MyClass();

// Short commnet max.: 1 line
/*
Long comment any line
*/

echo gettype($integer)."<br>"; // returns "integer"
echo gettype($float)."<br>"; // returns "double"
echo gettype($string)."<br>"; // returns "string"
echo gettype($array)."<br>"; // returns "array"
echo gettype($null)."<br>"; // returns "NULL"
echo gettype($class)."<br>"; // returns "object"
?>

You can get the type with “echo gettype($variable);”.

Loops and IF

In PHP you can use loops like in any other language.

IF

Tests two variable.

  1. “$a == $b” TRUE if it's equals (like both is equals 1)
  2. “$a != $b” TRUE if it's not equal (like $a is 5 and $b is 50)
  3. “$a === $b” TRUE if fully equal (like both is string and the value is “this”)
  4. “$a > $b” TRUE if $a is bigger than $b
  5. “$a < $b” TRUE if $a is smaller than $b
  6. “$a >= $b” TRUE if $a is bigger or equal to $b
  7. “$a ⇐ $b” TRUE if $a is smaller or equal to $b
<?php
$var = 1212;
$var2 = abc;

if($var == $var2){ // FALSE
$var2 = 9; //This will not run untill $var and $var2 is not equal
echo "This is not";
}else{ //Run if the the IF is FALSE
echo "This is works";
}
if($var == 1212){// TRUE
echo "This is works";
}elseif(){// Another if you can use (else if) but (elseif) is better
echo "You not see me";
}else{ // Run when (if) and (elseif) is fails
echo "They failed only me remain";
}


?>

WHILE

While loops are run utill there conditions are TRUE.

<?php
$a = 0;
while(a < 10){
print $a; // this will print the numbers from 0 to 9
$a++; // allways increment the counter(avoid infinite loops like "while(true)") 
}
?>

FOR

For loops are almost same to while loops but they take 3 parameter. First a variable definiton Second a rule Third an incerement/decrement rule.

<?php
for($i = 0; $i < 10; $i++){
print $i;
}
?>

QR Code
QR Code php_tutorial_for_for_begginers (generated for current page)
 

Advertise with Anonymous Ads