Contents
What is PHP?..........................................................................................................................................6
Basic PHP Syntax .................................................................................................................................6
Hello World example ..........................................................................................................................6
Error Management................................................................................................................................8
Finding errors present in the program ...............................................................................................9
Comments in PHP................................................................................................................................12
PHP is a Loosely Typed Language......................................................................................................12
PHP Variables Example.......................................................................................................................12
Global and locally-scoped variables...................................................................................................13
Example for Global and locally-scoped variables .............................................................................13
Static Keyword in PHP ........................................................................................................................14
Static Keyword Example....................................................................................................................14
ECHO and PRINT statements in PHP .................................................................................................15
PRINT Statement Example in PHP.....................................................................................................15
String Functions in PHP......................................................................................................................16
1. strlen() function ........................................................................................................................16
2. strpos() function........................................................................................................................16
Constant in PHP...................................................................................................................................17
Constant string Example ...................................................................................................................17
PHP Example to calculate the area of the circle ...............................................................................17
Arithmetic Operators ..........................................................................................................................18
Arithmetic Operators Example .........................................................................................................19
Increment and Decrement Operators................................................................................................20
Increment and Decrement Operators Example................................................................................20
Assignment Operators in PHP............................................................................................................21
Assignment Operators Example........................................................................................................21
String Operators in PHP......................................................................................................................23
String Operators Example .................................................................................................................23
The if Statement in PHP......................................................................................................................24
The if Statement Example.................................................................................................................24
The if…else Statement in PHP ............................................................................................................25
The if…else Statement Example........................................................................................................25
The if…elseif…else Statement in PHP ................................................................................................26
The if…elseif…else Statement Example (Comparing two numbers) ................................................. 26
Switch Statement in PHP .................................................................................................................... 27
Switch Statement Example ............................................................................................................... 27
For loop in PHP .................................................................................................................................... 28
For loop Example .............................................................................................................................. 28
Declaring multiple variables in for loop Example .............................................................................29
While Loop in PHP ............................................................................................................................... 30
While Loop Example ......................................................................................................................... 30
Do While loop in PHP .......................................................................................................................... 31
Do While loop Example ..................................................................................................................... 31
User Defined Function Example ........................................................................................................ 32
Swap Numbers PHP Example ............................................................................................................. 33
PHP Functions - Adding parameters .................................................................................................. 34
PHP Functions - Return values ........................................................................................................... 35
Break statement .................................................................................................................................. 35
Break statement example ................................................................................................................. 35
Continue statement ............................................................................................................................. 36
Continue statement example ........................................................................................................... 36
PHP Global Variables - Superglobals ................................................................................................. 36
$GLOBALS .......................................................................................................................................... 37
Example: ............................................................................................................................................ 37
$_SERVER .......................................................................................................................................... 38
Example ............................................................................................................................................. 38
Array in PHP .......................................................................................................................................... 39
Numeric Array in PHP ....................................................................................................................... 39
Numeric Array Example .................................................................................................................... 39
Associative array in PHP ........................................................................................................................ 40
Associative array Example ................................................................................................................ 40
Loop through an Associative Array ....................................................................................................... 41
Multidimensional array in PHP ............................................................................................................. 42
Multidimensional array Example ...................................................................................................... 42
PHP Forms ............................................................................................................................................. 43
The $_GET Function .......................................................................................................................... 43
The $_POST Function ........................................................................................................................ 43
The $_GET Function Example ........................................................................................................... 44
The $_ POST Function Example ........................................................................................................ 46
Another Example for PHP form ......................................................................................................... 48
Date() and time() function in PHP ......................................................................................................... 51
Example ............................................................................................................................................. 51
How to connect to MYSQL database using PHP ................................................................................... 52
The functions used to connect web form to the MYSQL database: ..................................................... 60
Display the data from MYSQL database in web form ........................................................................... 61
Insert the data into MYSQL database using web form ......................................................................... 63
Update the data present in MYSQL database using web form ............................................................. 66
Delete the data from MYSQL database using web form ...................................................................... 70
Hosting your domain using cPanel ........................................................................................................ 74
EMBEDDED SYSTEM WITH PHP ............................................................................................................ 86
OVERVIEW ......................................................................................................................................... 86
FEATURES .......................................................................................................................................... 86
APPLICATION DIAGRAM .................................................................................................................... 86
CIRCUIT DIAGRAM ............................................................................................................................ 87
PIN CONNECTION .............................................................................................................................. 88
INTERFACE ......................................................................................................................................... 89
LIBRARY ............................................................................................................................................. 89
CODE ................................................................................................................................................. 90
With Arduino ............................................................................................................................. 90
1. ADD hello world example from Examples ................................................................................ 90
2. Add Server Reading Example .................................................................................................... 90
3. relay interface(Web Remote) ................................................................................................... 91
.............................................................................................................................................................. 91
code:.................................................................................................................................................. 91
PIN CONNECTION .............................................................................................................................. 95
WITH ETHERNET MODULE ................................................................................................................ 95
WITH RELAY....................................................................................................................................... 96
CODE ................................................................................................................................................. 98
PHP CODE: ....................................................................................................................................... 102
PIN CONNECTION ............................................................................................................................ 106
code ................................................................................................................................................. 107