Learn PHP with Me
PHP - Hypertext Preprocessor
Version - PHP 5
Uses:
Version - PHP 5
Uses:
- Generate dynamic page content
- Create/Read/Open/Delete/Write/Close files on Server
- Collect form Data
- Send/Recieve Cookies
- Add/Delete/Modify Data in DB
- User Access Control
- DataEncryption
- Free/easy/compatible on all servers,runs on various platforms.
Installation: (MAMP server includes Apache+MySQL)
Install MAMP server on your pc and start coding PHP.
Place php files in htdocs directory of MAMP installation folder and play around.
Basics:
syntax:
<?php
echo "Praise the Lord!";
?>
comments : // or */ blah blah /*
variables : case senstive
$my_num = 12345678;
$my_name = Hanvitha;
strings : use . for concatenating
echo "My name is " . $my_name;
strlen, strpos, strrev, str_word_count, str_replace
scope:
local -
global - global $x, $y;
$GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
static -
objects -
class A{ function A(){ $this->x = "blah"; }
$my_A = new A();
echo $my_A->x;
$my_A = new A();
echo $my_A->x;
constants: they are global
no $ sign before a constant - created by :define("GREETING", "Welcome to my page"); echo GREETING;
operators: $x ** $y; === Identity; <> inequality; !== non identity;
rest are same as Java/C++
conditions & loops : all are same like Java/C++ except
foreach($colorsArray as $color){ echo "$color<br>"; }
functions:
function writeMsg() {
echo "Hello world!";
}
writeMsg();
echo "Hello world!";
}
writeMsg();
arrays:
$bible_chapters= array("Genesis", "Deuteronomy" , "Numbers" ...);
echo "I love $bible_chapters[0] where God created Earth";
$books = count($bible_chapters);
associate arrays: $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
Super Globals :
- $_SERVER is a PHP super global variable which holds information about headers, paths, and script locations.
- $_REQUEST is used to collect data after submitting an HTML form.
- $_POST is widely used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.
- $_GET can also be used to collect form data after submitting an HTML form with method="get".
Comments
Post a Comment