5. php bangla tutorial php basic

Upload: arif22tex

Post on 18-Oct-2015

51 views

Category:

Documents


6 download

TRANSCRIPT

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    1/67

    AAAA....

    1. 2. 3. Syntax

    4. (Variables)

    5. (String)

    6. (Operators)

    7. 8. (Loop)

    9.

    While

    10.For

    11.(Array)

    12.(Function)

    13.PHP 14.$_GET

    15.$_POST BBBB....

    1111.... |||| ( Advanced PHP Tut or i al i n Bangl a)( Advanced PHP Tut or i al i n Bangl a)( Advanced PHP Tut or i al i n Bangl a)( Advanced PHP Tut or i al i n Bangl a) 2222.... ( PHP Dat e Funct i on Tut or i a l i n Bangl a)( PHP Dat e Funct i on Tut or i a l i n Bangl a)( PHP Dat e Funct i on Tut or i al i n Bangl a)( PHP Dat e Funct i on Tut or i a l i n Bangl a) 3333.... ( PHP I ncl ude Funct i on Tut or i a l i n Bangl a)( PHP I ncl ude Funct i on Tut or i a l i n Bangl a)( PHP I ncl ude Funct i on Tut or i al i n Bangl a)( PHP I nc l ude Func t i on Tut or i al i n Bangl a) 4444.... ( PHP r eq( PHP r eq( PHP r eq( PHP r equi r e Func t i on Tut or i al i n Bangl a)ui r e Func t i on Tut or i al i n Bangl a)ui r e Func t i on Tut or i al i n Bangl a)ui r e Func t i on Tut or i al i n Bangl a) 5555.... ( PHP Fi l e Func t i on Tut or i al i n Bangl a)( PHP Fi l e Func t i on Tut or i al i n Bangl a)( PHP Fi l e Func t i on Tut or i al i n Bangl a)( PHP Fi l e Func t i on Tut or i al i n Bangl a) 6666.... ( PHP Fi l e Upl oad Tut or i a l i n Bangl a)( PHP Fi l e Upl oad Tut or i al i n Bangl a)( PHP Fi l e Upl oad Tut or i a l i n Bangl a)( PHP Fi l e Upl oad Tut or i al i n Bangl a) 7777....

    ( PHP Cook i e Tut or i al i n Bangl a)( PHP Cooki e Tut or i al i n Bangl a)( PHP Cooki e Tut or i al i n Bangl a)( PHP Cooki e Tut or i al i n Bangl a) 8888.... ( PHP Sessi on Tut or i al i n Bangl a) ( PHP Sessi on Tut or i al i n Bangl a) ( PHP Sessi on Tut or i al i n Bangl a) ( PHP Sessi on Tut or i a l i n Bangl a) 9999.... ( PHP Er r or Handl er Tut or i a l i n Bangl a)( PHP Er r or Handl er Tut or i a l i n Bangl a)( PHP Er r or Handl er Tut or i a l i n Bangl a)( PHP Er r or Handl er Tut or i a l i n Bangl a) 10.10.10.10. ( PHP Mai l Funct i on Tut or i al i n Bangl a)( PHP Mai l Funct i on Tut or i al i n Bangl a)( PHP Mai l Funct i on Tut or i al i n Bangl a)( PHP Mai l Func t i on Tut or i al i n Bangl a) 11111111.... ( PHP Fi l t er Tut or i al i n Bangl a)( PHP Fi l t er Tut or i al i n Bangl a)( PHP Fi l t er Tut or i al i n Bangl a)( PHP Fi l t er Tut or i al i n Bangl a)

    CCCC....

    1111.... |||| ( PHP Fr amewor k Tut or i al i n Bangl a)( PHP Fr amewor k Tut or i al i n Bangl a)( PHP Fr amewor k Tut or i al i n Bangl a)( PHP Fr amewor k Tut or i al i n Bangl a) 2222.... ( OOP & PHP Tut or i al i n Bangl a)( OOP & PHP Tut or i al i n Bangl a)( OOP & PHP Tut or i al i n Bangl a)( OOP & PHP Tut or i al i n Bangl a) ( OOPHP Tut or i al i n Bangl a)( OOPHP Tut or i al i n Bangl a)( OOPHP Tut or i al i n Bangl a)( OOPHP Tut or i al i n Bangl a) ::::---- |||||||| ::::6666---- 10101010 |||||||| : 11: 11: 11: 11 ---- 1 5 | |1 5 | |1 5 | |1 5 | | : 16: 16: 16: 16---- 23232323

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    2/67

    4444.... ( CodeI gni t er Downl oad & I ns t al l Tut or i al i n( CodeI gni t er Downl oad & I ns t al l Tut or i al i n( CodeI gni t er Downl oad & I ns t al l Tut or i al i n( CodeI gni t er Downl oad & I ns t al l Tut or i al i nBangl a)Bangl a)Bangl a)Bangl a)

    5. ( MVC St r uct ur e Tut or i al i n Bangl a)( MVC St r uct ur e Tut or i al i n Bangl a)( MVC St r uct ur e Tut or i al i n Bangl a)( MVC St r uc t ur e Tut or i al i n Bangl a) 6666.... ( CodeI gni t er Conf i gur e Tut or i al i n Bangl a)( CodeI gni t er Conf i gur e Tut or i al i n Bangl a)( CodeI gni t er Conf i gur e Tut or i al i n Bangl a)( CodeI gni t er Conf i gur e Tut or i al i n Bangl a) 7777.... ( Cr eat i ng Fi r s t Appl i cat i on wi t h CodeI gni t er )( Cr eat i ng Fi r s t Appl i cat i on wi t h CodeI gni t er )( Cr eat i ng Fi r s t Appl i cat i on wi t h CodeI gni t er )( Cr eat i ng Fi r s t Appl i cat i on wi t h CodeI gni t er )

    AAAA....

    1.1.1.1. |||| ( PHP Bas i c)( PHP Basi c)( PHP Basi c)( PHP Basi c):

    :

    instruction run

    handle Process :

    (Picture,Content etc) (math calculation,file operation etc)

    HTML

    (PHP) ?:

    PHP Hypertext Preprocessor , ,HTML-embedded

    syntax C,Perl,Java

    (PHP) :

    .HTML .HTML Form.

    . C

    .

    ?:?:?:?:

    hosting()

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    3/67

    -

    *

    .PHP -compitable : apache

    .PHP

    *

    .()

    .:Specialized

    webcoachbd.com

    2.

    ( PHP I nst al l at i on Tut or i al i n Bangl a)( PHP I ns t al l at i on Tut or i al i n Bangl a)( PHP I ns t al l at i on Tut or i al i n Bangl a)( PHP I ns t al l at i on Tut or i al i n Bangl a):

    apache :MySQL,

    XAMPP.XAMPP

    http://www.apachefriends.org/download.php?xampp-win32-1.7.3.exe

    XAMPP -

    XAMPP Control Panel C C:\Program Files\xampp C:\xampp start click (Apache

    MySql)

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    4/67

    Apache MySql http://localhost

    English

    ()

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    5/67

    ( PHP Code Wr i t t i ng)( PHP Code Wr i t t i ng)( PHP Code Wr i t t i ng)( PHP Code Wr i t t i ng):

    C driveC driveC driveC drive XAMPPXAMPPXAMPPXAMPP htdocshtdocshtdocshtdocs web contentweb contentweb contentweb content

    www C:\xampp\htdocs(:D drive

    D:\xampp\htdocs). mytest.php

    -http://localhost/mytest.php

    ,??

    : Net Beans, Dreamweaver , IDE (Integrated Development

    Environment).

    4.

    ( PHP Synt ax Tut or i al i n Bangl a)( PHP Synt ax Tut or i al i n Bangl a)( PHP Synt ax Tut or i al i n Bangl a)( PHP Synt ax Tut or i al i n Bangl a):

    extension .php .html execute

    *

    * Scripting Block( )

    *instruction(code line)

    (/)

    mypage.php ,htdocs browse save in http://localhost/mypage.php

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    6/67

    echo print.

    : execute

    ,

    // # /* */

    : ,

    echo "Hello World! ";echo "Hello World! ";echo "Hello World! ";

    echo "Hello World! ";echo "Hello World! ";

    ,

    5.

    ( PHP Var i abl es Tut or i al i n Bangl a)( PHP Var i abl es Tut or i al i n Bangl a)( PHP Var i abl es Tut or i al i n Bangl a)( PHP Var i abl es Tut or i al i n Bangl a):

    (Container) String Hello

    Bangladesh integer value 100. (

    declare ) , (value)

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    7/67

    $

    *case sensitive.$a_numberand $A_number ,

    *

    $variable_name = Value;

    -

    1.

    *Loosely Typed declare ()

    :

    .letter or _(under score)

    . alpha-numeric characters underscores. a-z, A-Z, 0-9, or _ .

    . ___underscore ($my_string)

    ($myString)

    6.

    ( PHP St r i ng Tut or i al i n Bangl a)( PHP St r i ng Tut or i al i n Bangl a)( PHP St r i ng Tut or i al i n Bangl a)( PHP St r i ng Tut or i al i n Bangl a):

    Career

    store

    ,store echo

    1.

    $my_string echo ,

    store

    store

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    8/67

    Double quotes Single quotes ,

    apostrophes

    1.

    single quotes -

    echo PHP it\s neat

    double quotes single quotes

    , quotation heredoc,

    -

    1.

    -

    *

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    9/67

    ( PHP Oper at or s)( PHP Oper at or s)( PHP Oper at or s)( PHP Oper at or s):

    - manipulate

    .Unary (operand)

    .Binary-

    .Ternary- Operator -Arithmetic, Assignment, ComparisonOperator etc.

    ( ASSI GNMENT OPERAT ( ASSI GNMENT OPERAT ( ASSI GNMENT OPERAT ( ASSI GNMENT OPERATOR)OR)OR)OR)

    $my_var = 4;

    $another_var = $my_var;

    $my_var $another_var .

    Operator English Example

    + Addition 2+4

    - Subtraction 6-2

    * Multiplication 5*3

    / Division 15/3

    % Modulus 43%10

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    10/67

    01.

    -

    ( COMPARI SON OPERATOR( COMPARI SON OPERATOR( COMPARI SON OPERATOR( COMPARI SON OPERATOR))))Operator relationship Operator statement

    statement true false. Comparison Operator -

    $x=4 $y=5

    Operator English Example Result

    == Equal to $x=$y False

    != Not equal to $x!=$y True

    < Less than $x

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    11/67

    > Greater than $x>$y False

    =$y False

    ( STRI NG OPERATOR)( STRI NG OPERATOR)( STRI NG OPERATOR)( STRI NG OPERATOR)-,

    ARI THMETI CARI THMETI CARI THMETI CARI THMETI C ASSI GNMENT OPERATORASSI GNMENT OPERATORASSI GNMENT OPERATORASSI GNMENT OPERATOR COMBI NATI ON COMBI NATI ON COMBI NATI ON COMBI NATI ONProgramming ,

    $counter=$counter+1;

    $counter+=1;

    Pre/Post-Increment Pre/Post-Decrement:

    ,

    $x++ $x += 1; $x = $x + 1

    -

    8.

    ( PHP Condi t i onal St at ement )( PHP Condi t i onal St at ement )( PHP Condi t i onal St at ement )( PHP Condi t i onal St at ement ):

    action feature

    Good Morning

    Good evening Conditional

    statement ,condition Conditional statement -

    *if statement

    *ifelse statement

    *ifelseifelse statement

    *Switch statement

    * I F STATEMENT* I F STATEMENT* I F STATEMENT* I F STATEMENT

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    12/67

    if statement execute condition true

    Have a nice day Saturday

    1.

    * I F* I F* I F* I FELSE STATEMENTELSE STATEMENTELSE STATEMENTELSE STATEMENT,,ifelse statement

    1.

    condition true Saturday Have a nice day Today is not Saturday.

    * I F* I F* I F* I FELSEI FELSEI FELSEI FELSEI FELSE STATEMENTELSE STATEMENTELSE STATEMENTELSE STATEMENT

    statement execute

    view sourceprint?01.02.03.13.14.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    13/67

    ( PHP Loop Tut or i al i n Bangl a)( PHP Loop Tut or i al i n Bangl a)( PHP Loop Tut or i al i n Bangl a)( PHP Loop Tut or i al i n Bangl a):

    statement execute

    -

    While Loop

    Dowhile Loop

    For Loop

    Foreach Loop

    WhileWhileWhileWhile :

    condition true while execute

    1.while(condition)2.{3.code to be executed;4.}

    condition false condition

    ,true execute condition :

    01.02.03.11.12.

    i=1. while($i

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    14/67

    -

    The number is 1

    The number is 2The number is 3The number is 4The number is 5

    I ?while loop execute

    DODODODOWHI LE LOOPWHI LE LOOPWHI LE LOOPWHI LE LOOP while loop condition test , , while

    execute

    1.Do2.{3.Code to be executed4.}5.While(condition);

    01.

    i=6 ?

    This is line 6

    This line is outside while loop.so it will not repeat.

    execute execution repeat

    ?while loop

    11.

    ( PHP For Loop)( PHP For Loop)( PHP For Loop)( PHP For Loop):

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    15/67

    while ,

    1.for(init; condition; increment)2.{3.code to be executed;4.}

    for loop statement expression assignment

    statement(loop control variable), execution Boolean

    expression (evaluate),true false

    return loop control variable

    i=1 I I 1.

    Output

    The number is 1The number is 2The number is 3

    The number is 4The number is 5

    expression expression , Boolean

    expression default true -

    foreach loop array

    ( PHP Ar r ay Tut or i al i n Bangl a)( PHP Ar r ay Tut or i al i n Bangl a)( PHP Ar r ay Tut or i al i n Bangl a)( PHP Ar r ay Tut or i al i n Bangl a):

    single value (container).valuecontainer

    value -key index

    single variable store

    -

    $city1= Dhaka

    $city2= Chittagong

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    16/67

    $city3= Rajshahi

    $city4= Sylet

    $city5= Khulna$city6= Barishal

    (series of

    element) index -

    1.

    variable store , index

    array index/key Dhaka[0],Chittagong[1]

    index number

    1.

    ,=>

    starting index 2

    1.

    index

    ( ASSOCI ATI VE ARRAY)( ASSOCI ATI VE ARRAY)( ASSOCI ATI VE ARRAY)( ASSOCI ATI VE ARRAY)index/key string associative array :

    1.

    ( MULTI DI MENSI ONAL AR( MULTI DI MENSI ONAL AR( MULTI DI MENSI ONAL AR( MULTI DI MENSI ONAL ARRAY)RAY)RAY)RAY)

    1.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    17/67

    FOREACH LOOPFOREACH LOOPFOREACH LOOPFOREACH LOOP

    associative array foreach statement :1.

    Output

    Dhaka

    ChittagongRajshahi

    Sylet

    Khulna

    Barishal

    Barishal

    13.

    ( PHP Func t i on)( PHP Funct i on)( PHP Funct i on)( PHP Funct i on):

    execution

    execute

    1.functionfunctionName()2.{3.code to be executed;4.}

    :

    _ ,

    simple

    01.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    18/67

    02.functionwriteName()03.{04.echo"Md.Rejoanul Alam";05.}06.07.echo"My name is ";08.writeName();09.?>

    Output

    My name is Md.Rejoanul Alam

    ,PHP variable

    01.

    output

    Hello there Jack Black!Hello there Ahmed Zewail!Hello there Julie Roberts!Hello there Charles Schwab!

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    19/67

    return return statement

    view source

    print?01.

    ( PHP For m)( PHP For m)( PHP For m)( PHP For m):

    () -

    $_GET $_POST.

    1.

    2.Name: 3.Age: 4.5.

    welcome.php

    method=POST ,Form

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    20/67

    POST GET.

    welcome.php

    1.Welcome !
    2.You are years old.

    rezwan age 24,

    Welcome rezwan!You are 24 years old.

    15.

    $_$_$_$_GETGETGETGET ( PHP $_GET Met hod)( PHP $_GET Met hod)( PHP $_GET Met hod)( PHP $_GET Met hod):

    GET

    character ( URL

    )

    1.2.Name: 3.Age: 4.5.

    http://www.w3schools.com/welcome.php?fname=Peter&age=37

    welcome.php $_GET Method

    1.Welcome .
    2.You are years old!

    16.

    ( PHP $_POST Met hod)( PHP $_POST Met hod)( PHP $_POST Met hod)( PHP $_POST Met hod):

    (Mb )

    Name:

    Age:

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    21/67

    http://www.w3schools.com/welcome.php$_POST Method

    Welcome !

    You are years old.

    GET Method passwordPOST Method

    BBBB....

    1.1.1.1.

    |||| ( Advanced PHP( Advanced PHP( Advanced PHP( Advanced PHP Tut or i al i n Bangl a)Tut or i al i n Bangl a)Tut or i al i n Bangl a)Tut or i al i n Bangl a):

    webcoachbd.com - ,,,,

    2.

    ( PHP Dat e Funct i on Tut or i al i n Bangl a)( PHP Dat e Funct i on Tut or i al i n Bangl a)( PHP Dat e Funct i on Tut or i al i n Bangl a)( PHP Dat e Funct i on Tut or i al i n Bangl a):

    ( PHP DATE FUNCTI ON)( PHP DATE FUNCTI ON)( PHP DATE FUNCTI ON)( PHP DATE FUNCTI ON) / date()

    view source

    print?1.

    Output

    2009/05/11

    2009.05.11

    2009-05-11

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    22/67

    3.

    ( PHP I nc l ude Func t i on Tut or i al i n( PHP I nc l ude Func t i on Tut or i al i n( PHP I nc l ude Func t i on Tut or i al i n( PHP I nc l ude Func t i on Tut or i al i nBangl a)Bangl a)Bangl a)Bangl a):

    include()

    Require()-fatal error()

    Include()-

    ,,

    (,,)

    include

    ,menu.php

    1.Home 2.Tutorials 3.References 4.Examples

    5.About Us6.Contact Us

    view sourceprint?01.02.03.04.05.06.Welcome to my home page.07.

    Some text.

    08.09.

    4.

    ( PHP r equi r e Funct i on Tut or i al i n Bangl a)( PHP r equi r e Funct i on Tut or i al i n Bangl a)( PHP r equi r e Funct i on Tut or i al i n Bangl a)( PHP r equi r e Funct i on Tut or i al i n Bangl a):

    require() include()

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    23/67

    Include()

    01.

    02.03.04.08.09.

    Error message:

    Warning:include(wrongFile.php) [ffailed to open

    No such file or directory in C:\home\website\test.php on

    Warning:include() [fFailed opening 'wrongFile.php' for(include_path='.;C:\php5\pear')in C:\home\website\test.php on line

    Hello World!

    Notice that the echo statement is executed! This is because a Warning does not stop the scriptexecution.

    require() Function Now, let's run the same example with the require() function.

    1.2.3.7.8.

    Error message:

    Warning:require(wrongFile.php) [ffailed to openNo such file or directory in C:\home\website\test.php on

    Fatal error:require() [fFailed opening required(include_path='.;C:\php5\pear')in C:\home\website\test.php on line 5

    echo statement

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    24/67

    5.

    ( PHP Fi l e Func t i on Tut or i al i n( PHP Fi l e Func t i on Tut or i al i n( PHP Fi l e Func t i on Tut or i al i n( PHP Fi l e Func t i on Tut or i al i nBangl a)Bangl a)Bangl a)Bangl a):

    fopen

    1.2.3.6.7.

    fopen welcome.txt r ()r read only

    Modes Description

    r Read only. Starts at the beginning of the file

    r+ Read/Write. Starts at the beginning of the file

    wWrite only. Opens and clears the contents of file; or creates a new

    exist

    w+Read/Write. Opens and clears the contents of file; or creates a newexist

    a Append. Opens and writes to the end of the file or creates a new file i

    a+ Read/Append. Preserves file content by writing to the end of the file

    x Write only. Creates a new file. Returns FALSE and an error if file alr

    x+ Read/Write. Creates a new file. Returns FALSE and an error if file al

    fopen() function 1.2.3.6.7.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    25/67

    fclose() function

    1.

    ENDENDENDEND---- OFOFOFOF---- FILEFILEFILEFILE

    if (feof($file)) echo "End of file";

    LINE BY LINELINE BY LINELINE BY LINELINE BY LINE fgets() function

    01.

    CHARACTER BY CHARACTCHARACTER BY CHARACTCHARACTER BY CHARACTCHARACTER BY CHARACTERERERER

    fgetc() function

    view sourceprint?1.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    26/67

    ( PHP Fi l e Upl oad Tut or i al i n( PHP Fi l e Upl oad Tut or i al i n( PHP Fi l e Upl oad Tut or i al i n( PHP Fi l e Upl oad Tut or i al i nBangl a)Bangl a)Bangl a)Bangl a):

    01.02.03.04. 06.Filename:

    07.

    08.09.10.11.12.

    action="upload_file.php" method="post" upload_file.php upload_file.php

    Upload_file.php

    01.

    global PHP $_FILES

    $_FILES["file"]["name"] $_FILES["file"]["type"] - type $_FILES["file"]["size"] - size $_FILES["file"]["tmp_name"] temporary copy

    .jpeg,.jpg,.gif

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    27/67

    01.

    (temporary copy) ,

    01.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    28/67

    24.move_uploaded_file($_FILES["file"]["tmp_name"], 25."upload/". $_FILES["file"]["name"]);

    26.echo"Stored in: ". "upload/". $_FILES["file"]["name"];27.}28.}29.}30.else31.{32.echo"Invalid file";33.}34.?>

    ,move_uploaded_file

    upload

    7.

    ( PHP Cooki e Tut or i al i n Bangl a)( PHP Cooki e Tut or i al i n Bangl a)( PHP Cooki e Tut or i al i n Bangl a)( PHP Cooki e Tut or i al i n Bangl a):

    ( /

    ) , ,

    ( )

    setcookie() function

    setcookie() function

    setcookie(name, value, expiration);

    namename:,

    value:,username(string)last visit(date)expiration: ()

    visit

    ignore

    1.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    29/67

    3.setcookie("user", "rezwan",$expire);4.?>5.

    6......

    ((((RETRIEVERETRIEVERETRIEVERETRIEVE))))

    $_COOKIE variable retrieve

    1.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    30/67

    5.6.7.

    $_SESSION

    01.06.07.08.09.13.14.15.

    Pageviews=1

    page view counter(page ) isset() views views variable

    counter viewsvariable

    01.

    ( DESTROYI NG A SESSI O( DESTROYI NG A SESSI O( DESTROYI NG A SESSI O( DESTROYI NG A SESSI ON)N)N)N)unset() or the session_destroy() function ]

    unset() function

    1.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    31/67

    session_destroy() function

    1.

    session_destroy() reset

    9.

    ( PHP Er r or Handl er Tut or i al i n( PHP Er r or Handl er Tut or i al i n( PHP Er r or Handl er Tut or i al i n( PHP Er r or Handl er Tut or i al i nBangl a)Bangl a)Bangl a)Bangl a):

    error handling

    ()

    "die()" statements

    Custom errors and error triggers

    Error reporting

    """"DIEDIEDIEDIE()"()"()"()"

    1.

    Warning: fopen(welcome.txt) [function.fopen]: failed to open stream:No such file or directory in C:\webfolder\test.phpon line 2

    01.

    File not found

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    32/67

    error

    call (error level and

    error message) (optionally: file, line-number, and the error context)

    error_function(error_level,error_message,error_file,error_line,error_context)

    Parameter Description

    error_level error report level

    value number error report level

    error_message error message

    error_file

    error_line

    error_context (Specifies an array)

    ( VALUE)( VALUE)( VALUE)( VALUE)

    Value Constant Description

    2 E_WARNING run-time errors. Execution

    8 E_NOTICE Run-time notices.

    256 E_USER_ERROR E_ERROR PHP

    function trigger_error()

    512 E_USER_WARNING Runtime warnings generated by a call totrigger_error( )

    1024 E_USER_NOTICE Runtime warnings generated by a call totrigger_error( )

    4096 E_RECOVERABLE_ERROR Catchable fatal error.8191 E_ALL errors warnings, level E_STRICT (E_STRICT

    PHP 6.0

    E_ALL )

    1.functioncustomError($errno,$errstr)2.{3.echo"Error: [$errno] $errstr
    ";

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    33/67

    4.echo"Ending Script";5.die();6.}

    error handling error level

    error handler error handler

    PHP error handler

    set_error_handler("customError");

    error handle , set_error_handler()

    ,error level

    01.

    Error:[8] Undefined variable: test

    TRIGGERTRIGGERTRIGGERTRIGGER trigger /

    trigger_error() function test error

    1.

    Notice: Value must be 1 or belowin C:\webfolder\test.phpon line 6

    error trigger error

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    34/67

    level trigger

    error

    E_USER_ERROR E_USER_WARNING E_USER_NOTICE

    test E_USER_WARNING error

    error handler

    01.

    Error:[512] Value must be 1 or belowEnding Script

    PHP error_log() error log()

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    35/67

    error_log("Error: [$errno] $errstr",1,"[email protected]","From: [email protected]");}

    //set error handlerset_error_handler("customError",E_USER_WARNING);

    //trigger error$test=2;if ($test>1){trigger_error("Value must be 1 or below",E_USER_WARNING);}?>

    Error:[512] Value must be 1 or belowWebmaster has been notified

    Error: [512] Value must be 1 or below

    ( PHP Fi l t er Tut or i al i n Bangl a)( PHP Fi l t er Tut or i al i n Bangl a)( PHP Fi l t er Tut or i al i n Bangl a)( PHP Fi l t er Tut or i al i n Bangl a):

    (validate/acceptable) (filter)

    filter

    -

    filter -

    filter_var() filter filter_var_array()

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    36/67

    filter_input filter_input_array filter_var() function validate

    01. "FILTER_VALIDATE_INT" $int ,"Integer is valid"

    123 integer.

    VALIDATINGVALIDATINGVALIDATINGVALIDATING SANI TI ZI NGSANI TI ZI NGSANI TI ZI NGSANI TI ZI NG

    VALI DATI NG FI LTERS:VALI DATI NG FI LTERS:VALI DATI NG FI LTERS:VALI DATI NG FI LTERS:

    user input validate

    (URL E-Mail validating)

    SANI TI ZI NG FI LTERS:SANI TI ZI NG FI LTERS:SANI TI ZI NG FI LTERS:SANI TI ZI NG FI LTERS:

    return

    OPTIONSOPTIONSOPTIONSOPTIONS FLAGSFLAGSFLAGSFLAGSOption Flag filtering option option

    flag validate filter_var() "min_range" "max_range"

    option

    01.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    37/67

    08."max_range"=>25609.)10.);

    11.12.if(!filter_var($var, FILTER_VALIDATE_INT,$int_options))13.{14.echo("Integer is not valid");15.}16.else17.{18.echo("Integer is valid");19.}20.?>

    options associative array options flag

    "Integer is not valid".

    VALI DATE I NPUTVALI DATE I NPUTVALI DATE I NPUTVALI DATE I NPUT filter_input() function

    01.

    :() "GET" method

    ."email" GET

    .

    SANI TI ZE I NPUTSANI TI ZE I NPUTSANI TI ZE I NPUTSANI TI ZE I NPUT filter_input() function

    sanitize

    01.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    38/67

    03.{04.echo("Input type does not exist");05.}

    06.else07.{08.$url= filter_input(INPUT_POST,09."url", FILTER_SANITIZE_URL);10.}11.?>

    :(url) "POST" method

    ."url" POST

    .sanitize( ) $url variable

    "http://www.W3Schools.com/" $url variable sanitizing

    http://www.W3Schools.com/

    call filter

    filter_var_array the filter_input_array function

    view source

    print?01.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    39/67

    25.}26.elseif(!$result["email"]) 27.{

    28.echo("E-Mail is not valid.
    ");29.}30.else31.{32.echo("User input is valid");33.}34.?>

    ( PHP Mai l Func t i on Tut or i al i n Bangl a)( PHP Mai l Funct i on Tut or i al i n Bangl a)( PHP Mai l Funct i on Tut or i al i n Bangl a)( PHP Mai l Funct i on Tut or i al i n Bangl a)

    PHP mail()

    1.mail(to,subject,message,headers,parameters)

    (\n)

    :From,Cc,Bcc

    : php.ini

    >> ? -

    ([email protected])

    PHP MAI L FORMPHP MAI L FORMPHP MAI L FORMPHP MAI L FORM

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    40/67

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    41/67

    CCCC.... 1.1.1.1. |||| ( PHP Fr amewor k Tut or i( PHP Fr amewor k Tut or i( PHP Fr amewor k Tut or i( PHP Fr amewor k Tut or i al i na l i na l i na l i nBangl a)Bangl a)Bangl a)Bangl a):

    (PHP Framework) basic Platform/structure()

    ,like (like) ,

    PHP Framework -,,

    ,,

    (PHP Framework)

    (PHP Framework) .PHP(PHP Function, Variable etc)

    .Object Oriented Programming

    .MVC(Model View Controller)Structure

    ,,,

    -

    , (CodeIgniter PHPFramework)

    ( OOP & PHP Tut or i al i n Bangl a)( OOP & PHP Tut or i al i n Bangl a)( OOP & PHP Tut or i al i n Bangl a)( OOP & PHP Tut or i al i n Bangl a):

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    42/67

    ---- POP ( PROCEDURE ORI ENPOP ( PROCEDURE ORI ENPOP ( PROCEDURE ORI ENPOP ( PROCEDURE ORI ENTED PROGRAMMI NG)TED PROGRAMMI NG)TED PROGRAMMI NG)TED PROGRAMMI NG)

    language FORTRAN(Formula Translation- Statistician )COBOL,CProcedure

    Oriented Programming(POP).PHP POP

    (instruction/actions) ,

    ,+

    POP global data

    ---- OOP( OBJECTOOP( OBJECTOOP( OBJECTOOP( OBJECT ORI ENTED PROGRAMMI NGORI ENTED PROGRAMMI NGORI ENTED PROGRAMMI NGORI ENTED PROGRAMMI NG))))OOP (Object Oriented Programming)

    OOP critical element (free flow) OOP

    Objects , /

    //(interact)

    OOPOOPOOPOOP*(operate )

    *Object Object*Object ,(Operate )

    *

    *Object Object

    *

    OOP

    Objects Class Encapsulation Inheritence Polymorphism Message passing

    ( OBJECTS)( OBJECTS)( OBJECTS)( OBJECTS) ,()

    (a bundle) ,

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    43/67

    ,

    ()

    //(bunch). (),

    (bunch) (), ,()

    ( -Procrdure Oriented way)

    (bunch)

    ( CLASS)( CLASS)( CLASS)( CLASS)

    / (blueprint/template/outline) ()

    (blueprint).

    , living,breathing

    living,breathing

    ( ENCAPSULATI ON)( ENCAPSULATI ON)( ENCAPSULATI ON)( ENCAPSULATI ON) (class)

    (data hiding/information hiding)

    ( I NHERI TANCE)( I NHERI TANCE)( I NHERI TANCE)( I NHERI TANCE)

    OOP :(reusability)

    (super class/base class)

    /(subclass/derived class).extends

    ( POLYMORPHI SM)( POLYMORPHI SM)( POLYMORPHI SM)( POLYMORPHI SM)

    ( MESSAGE PASSI NG)( MESSAGE PASSI NG)( MESSAGE PASSI NG)( MESSAGE PASSI NG)

    OO Program

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    44/67

    3.

    ( OOPHP Tut or i al i n Bangl a)( OOPHP Tut or i al i n Bangl a)( OOPHP Tut or i al i n Bangl a)( OOPHP Tut or i al i n Bangl a)

    (PHP5)

    ,,

    OOPHP ,,,

    ()

    ---- ::::

    index.php

    class_lib.php

    includes

    class_lib.php OOP

    /

    ---- ::::

    ,,

    class

    1.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    45/67

    ---- ::::

    /

    property

    1.

    :/(var name;) properties

    ---- ::::

    ////

    properties

    methods ()

    /methods /properties

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    46/67

    properties

    ---- ::::

    gettergettergettergetter settersettersettersetter

    / get_name() set_name()

    getter setter property

    getter setter property

    set_name() / property/variable name

    ---- ::::

    $t hi s$t hi s$t hi s$t hi s

    $this->name=$new_name

    $this () self-

    referencing properties

    function get_name() {

    return $this->name;

    }

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    47/67

    ---- ::::

    include require

    OOPHP in Webcoachbd

    ,

    ---- ::::

    instantiation.

    $rejoan = new people();

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    48/67

    $rejoan people $rejoan people

    ---- ::::

    newnewnewnew

    new

    (

    )

    $rejoan = new people();

    $riad = new people;

    quote

    $rejoan= new 'people';

    ---- ::::

    propertiespropertiespropertiesproperties ((((setsetsetset))))

    people , properties (set) (the setters)

    ($rejoan $riad) people

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    49/67

    $rejoan = new people();

    $riad= new people;

    $rejoan->set_name("Rejoanul Alam");$riad->set_name("Anjirul Alam");

    ?>

    ---- : : ::

    getter setter

    properties (->)

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    50/67

    -:

    propertiespropertiespropertiesproperties ????

    properties ,(->)

    :

    $rejoan->name.

    getter

    ---- ::::

    properties

    :__construct() __construct /

    construct (__)

    ()

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    51/67

    functions=methods

    variables=properties

    -:

    constructconstructconstructconstruct

    ,people $name property

    :

    $rejoan = new people("Rejoanul Alam");

    set_name()

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    52/67

    (mechanism)

    ---- ::::

    propertiespropertiespropertiesproperties

    (encapsulation).

    (properties)

    properties access modifier -

    1. public

    2. private

    3. protected

    public

    : var properties (declare)public

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    53/67

    -:

    propertiespropertiespropertiesproperties ---- property private

    property protected (derived class/

    properties )

    public

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    54/67

    :get_pinn_number() private ,

    public

    ---- ::::

    ::::::::

    (Inheritence)

    /

    ?

    : :

    employee employee people/person properties

    ?

    :

    .

    . : ()

    includes()

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    55/67

    // 'extends'

    class employee extends people {function __construct($employee_name) {

    }

    ---- ::::

    ::::----

    employee people employee people

    public properties,()

    // 'extends'

    class employee extends people {

    function __construct($employee_name) {

    $this->set_name($employee_name);

    }

    }

    employee set_name() employee (declare) people

    -:

    ::::----

    employee get_name() people

    (/)

    OOPHP in Webcoachbd

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    56/67

    echo "Riads full name " . $riad->get_name();

    ?>

    ---- ::::

    Over r i ddi ngOver r i ddi ngOver r i ddi ngOver r i ddi ng

    ()

    set_name() people employee

    people set_name() Override employee

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    57/67

    function __construct($employee_name) {

    $this->set_name($employee_name);

    }}

    ?>

    set_name() people () employee

    -:

    OverridingOverridingOverridingOverriding....----

    , (child

    ) override

    employee set_name() override

    people::set_name($new_name);

    parent (People) set_name()

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    58/67

    if ($new_name == "Stefan Sucks") {

    $this->name = $new_name;

    }else if($new_name == "Anjirul Alam") {

    people::set_name($new_name);

    }

    }

    function __construct($employee_name) {

    $this->set_name($employee_name);

    }

    }

    ?>

    ---- ::::

    overridingoverridingoverridingoverriding ----

    'people::set_name()' people set_name()

    parent parent (

    parent )

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    59/67

    class employee extends people {

    protected function set_name($new_name) {

    if ($new_name == "Stefan Sucks") {$this->name = $new_name;

    }

    else if($new_name == "Anjirul Alam") {

    parent::set_name($new_name);

    }

    }

    function __construct($employee_name) {

    $this->set_name($employee_name);

    }

    }

    ?>

    :::: OOPHP

    OOP

    ,

    /

    OOPOOPOOPOOP

    ,,,++

    ( )

    ( ) OOP

    ,

    -

    properties

    (parent-child/base-derived)

    4.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    60/67

    ( MVC St r uc t ur e Tut or i al i n( MVC St r uc t ur e Tut or i al i n( MVC St r uc t ur e Tut or i al i n( MVC St r uc t ur e Tut or i al i nBangl a)Bangl a)Bangl a)Bangl a):

    MVC Structure ( )

    01.07.08.Home Page09.13.14.17.18.19.20.21.24.25.

    MVC Structure

    (Model)

    (View)

    (Controller)

    ( MODEL) :( MODEL) :( MODEL) :( MODEL) : ,

    () ,,

    (business logic)

    ( VI EW) :( VI EW) :( VI EW) :( VI EW) :

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    61/67

    ,,

    ( CONTROLLER) :( CONTROLLER) :( CONTROLLER) :( CONTROLLER) :

    MVC

    5.

    ( CodeI gni t er Downl oad & I nst al l( CodeI gni t er Downl oad & I ns t al l( CodeI gni t er Downl oad & I ns t al l( CodeI gni t er Downl oad & I ns t al lTut or i al i n Bangl a)Tut or i al i n Bangl a)Tut or i al i n Bangl a)Tut or i al i n Bangl a):

    http://codeigniter.com/downloads/ , .zip format

    ,

    htdocs folder, F:\Program Files\xampp\htdocs. C Drive C

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    62/67

    drive F F C:\Program Files\xampp\htdocs.

    ( ) CodeIgniter.

    system>>application>> config>>config.php

    view sourceprint?01.|-------------------------------------------------------------------------

    -02.| Base Site URL03.|-------------------------------------------------------------------------

    -04.

    05.

    06.$config['base_url'] = "http://localhost/CodeIgniter/";07.08.09.

    10.11.|-------------------------------------------------------------------------

    -12.| Index File13.|-------------------------------------------------------------------------

    -14.15.

    16.$config['index_page'] = "index.php";17.18.19.20.21.|-------------------------------------------------------------------------

    -22.| Default Language23.|-------------------------------------------------------------------------

    -24.25.

    26.$config['language'] = "english";27.28.

    29.30.31.|-------------------------------------------------------------------------

    -32.| Default Character Set33.|-------------------------------------------------------------------------

    -34.

    35.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    63/67

    36.$config['charset'] = "UTF-8";37.

    38.39.40.41.|-------------------------------------------------------------------------

    -42.| Cache Directory Path43.|-------------------------------------------------------------------------

    -44.45.46.$config['cache_path'] = 'http://127.0.0.1/codeigniter/cache/';47.48.

    49.50.51.|-------------------------------------------------------------------------

    -52.| Session Variables53.|-------------------------------------------------------------------------

    -54.55.56.$config['sess_cookie_name'] = 'ci_session';57.$config['sess_expiration'] = 7200;58.$config['sess_encrypt_cookie'] = FALSE;

    59.$config['sess_use_database'] = FALSE;60.$config['sess_table_name'] = 'ci_sessions';61.$config['sess_match_ip'] = FALSE;62.$config['sess_match_useragent'] = TRUE;63.$config['sess_time_to_update'] = 300;64.65.66.

    67.68.|-------------------------------------------------------------------------

    -69.| Global XSS Filtering70.|-------------------------------------------------------------------------

    -71.

    72.73.$config['global_xss_filtering'] = FALSE;74.75.76.77.78.|-------------------------------------------------------------------------

    -79.| Output Compression

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    64/67

    80.|-------------------------------------------------------------------------

    -81.

    82.83.$config['compress_output'] = TRUE;84.85.86.87.88.|-------------------------------------------------------------------------

    -89.| Rewrite PHP Short Tags90.|-------------------------------------------------------------------------

    -91.

    92.93.$config['rewrite_short_tags'] = FALSE;

    6.

    ( CodeI gni t er Conf i gur e Tut or i al i n( CodeI gni t er Conf i gur e Tut or i al i n( CodeI gni t er Conf i gur e Tut or i al i n( CodeI gni t er Conf i gur e Tut or i al i nBangl a)Bangl a)Bangl a)Bangl a):

    config.php database.php

    01.$active_group = "default";02.$active_record = TRUE;03.

    04.05.$db['default']['hostname'] = "localhost";06.$db['default']['username'] = "root";07.$db['default']['password'] = "mypassword";08.$db['default']['database'] = "mydatabase";09.$db['default']['dbdriver'] = "mysql";10.$db['default']['dbprefix'] = "";11.$db['default']['pconnect'] = TRUE;12.$db['default']['db_debug'] = TRUE;

    13.$db['default']['cache_on'] = FALSE;14.$db['default']['cachedir'] = "";15.$db['default']['char_set'] = "utf8";16.$db['default']['dbcollat'] = "utf8_general_ci";

    address bar http://localhost/CodeIgniter/

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    65/67

    7.

    ( Cr eat i ng Fi r st( Cr eat i ng Fi r st( Cr eat i ng Fi r st( Cr eat i ng Fi r st Appl i cat i on wi t hAppl i c at i on wi t hAppl i c at i on wi t hAppl i c at i on wi t hCodeI gni t er )CodeI gni t er )CodeI gni t er )CodeI gni t er ):

    OOP OOPHP

    ,

    MVC Structure ,

    ( ), ( ) (

    )

    F:\Program Files\xampp\htdocs\CodeIgniter\system\application\controllers

    helloworld.php (F C ) ++

    class

    01.

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    66/67

    06.}07.functionindex(){08.$data['title']='My first application created with Code Igniter';

    09.$data['message']='Hello world!';10.// load 'helloworld' view11.$this->load->view('helloworld',$data); 12.}13.}14.?>

    : //'Controller'

    'Controller' /

    'Controller' extends 'HellowWorld'

    (derived).

    parent::Controller() function index() (Controller )

    index() () $data () 'helloworld.php' loader , loader

    loader

    $this->load->view('helloworld',$data);

    pass

    F:\Program Files\xampp\htdocs\CodeIgniter\system\application\views helloworld.php

    1.2.3.4.5.6.7.8.

    Address bar

    http://localhost/CodeIgniter/index.php/helloworld

    : Controller Views folder welcome.php welcome_message.php

    ++

  • 5/28/2018 5. PHP Bangla Tutorial Php Basic

    67/67