Jumat, 30 Maret 2012

Module 2 Practical E-Commerce


STMIK AMIKOM Yogyakarta | Tohir Ismail | 2011
Module 2 Practical E-Commerce

PHP-UP

1. CONTROL STRUCTURE
            a. FOR
            b. WHILE, DO .. WHILE
            c. IF, ELSE, ELSE IF
            d. SWITCH

2. USER FUNCTION

3. INTERNAL FUNCTIONS
            a. STRING PARSING
                        i. Explode, implode
                        ii. Strlen, substr
            b. STRING formating
                        i. Printf, sprintf
                        ii. Str_replace, STR_IREPLACE
                        iii. Htmlentities, html_entity_decode, htmlspecialchars
            c. MATHEMATICS
                        i. ABS, ceil, FLOOR, MAX, MIN, ROUND, RAND, FMOD
            d. DATE & TIME
                        i. DATE & TIME formating
                        ii. OPERATION DATE
            e. Sending MAIL

A. CONTROL STRUCTURE

            1.1. FOR
                        for ($ i = 1; $ i <= 10; $ i + +) {
                        echo $ i;
                        }

            1.2. WHILE
                        $ I = 1;
                        while ($ i <= 10) {
                        echo $ i + +;
                        }

            DO ... WHILE
                        $ I = 0;
                        do {
                        echo $ i;
                        } While ($ i> 0);

            1.3. IF
                        if ($ a> $ b)
                        echo "a is greater than b";

            ELSE
                        if ($ a> $ b) {
                        echo "a is greater than b";
                        Else {}
                        echo "a is not greater than b";
                        }

            ELSE IF
                        if ($ a> $ b) {
                        echo "a is greater than b";
                        } Elseif ($ a == $ b) {
                        echo "a equal to b";
                        Else {}
                        echo "a is smaller than b";
                        }

            1.4. SWITCH
                        switch ($ i) {
                        case 0:
                        echo "i equals 0";
                        break;
                        case 1:
                        echo "i equals 1";
                        break;
                        case 2:
                        echo "i equals 2";
                        break;
                        }
                        switch ($ i) {
                        case "apple":
                        echo "i contents apples";
                        break;
                        case "orange":
                        echo "i it orange";
                        break;
                        case "barked":
                        echo "i it barked";
                        break;
                        }


2. USER FUNCTION
                        function multiply ($ num1, $ num2)
                        {
                        return $ num1 * $ num2;
                        }
                        echo multiplication (3.4) / / output '12 '.
           
3. INTERNAL FUNCTIONS
            3.1. STRING PARSING
            3.1.1. Explode
                        Syntax: array explode (string $ delimiter, string $ string [, int $ limit])
                        Example:
                                    $ Yogyakarta = "Yogyakarta, Sleman, Bantul, South Mountain,                                                      Kulonprogo";
                                    $ District = explode (",", $ Yogyakarta);
                                    echo $ district [0]; / / Yogyakarta
                                    echo $ district [3]; / / Gunungkidul

                        Implode
                                    Syntax: string implode (string $ glue, array $ pieces)
                        Example:
                                    $ Array = array ('module', 'Practice', 'E-Commerce');
                                    $ Join = implode ("-", $ array);
                                    echo $ join; / / module-Lab-E-Commerce


            3.1.2. Strlen
                                    Syntax: int strlen (string $ string)
                        Example:
                                    $ Str = 'E-Commerce';
                                    echo strlen ($ str) / / 10

            SUBSTR
                                    Syntax: string substr (string $ string, int $ start [, int $ length])
                        Example:
                                    $ Rest = substr ("abcdef", -1); / / result: "f"
                                    $ Rest = substr ('abcdef', -2); / / result: "ef"
                                    $ Rest = substr ("abcdef", -3, 1); / / result: "d"
                                    $ Rest = substr ("abcdef", 0, -1); / / result: "abcde"
                                    $ Rest = substr ("abcdef", 2, -1); / / result: "CDE"
                                    $ Rest = substr ("abcdef", 4, -4); / / result: ""
                                    $ Rest = substr ("abcdef", -3, -1); / / result: "de"

            3.2. STRING formating

            3.2.1. Printf, sprintf
                        Example 1:
                                    $ Number = 12345;
                                    $ Tulisan1 = 'PHP';
                                    $ Tulisan2 = 'E-Commerce';
                                    $ Format = '% s Learning to learn% s lucky number
                                    % D ';
                                    printf ($ format, $ tulisan1, $ tulisan2, $ number);

                        Example 2:
                                    <? Php
                                    $ S = 'amikom';
                                    $ T = 'amikom student';
                                    printf ("[% s] \ n", $ s); / / output common
                                    printf ("[% 15s] \ n", $ s); / / 15 characters with spaces flush right
                                    printf ("[%-15s] \ n", $ s); / / 15 characters with spaces left flat
                                    printf ("[% 015s] \ n", $ s); / / 15 characters padding 0
                                    printf ("[% '# 15s] \ n", $ s); / / 15 characters padding #
                                    printf ("[% 15.10s] \ n", $ t) / / 15 characters cut of 10 characters
                                    ?>
                        Results:
                                    [Amikom]
                                    [Amikom]
                                    [Amikom]
                                    [000000000amikom]
                                    [# # # # # # # # # Amikom]
                                    [Student]

                        Example 3:
                                    $ Uang1 = 68.75;
                                    $ Uang2 = 54.35;
                                    $ Money = $ + $ uang2 uang1;
                                    / / Echo $ money will output "123.1";
                                    echo $ money;
                                    $ Formatted = sprintf ("Rp.% 01.2f", $ currency);
                                    / / Echo $ formatted output "Rp.123.10"
                                    echo $ formatted;

            3.2.2. Str_replace, STR_IREPLACE
                        Example 1:
                                    $ BodyTag = str_replace ("% body%", "black", "<body                                                                    text='%body%'>");

                        Example 2:
                                    $ Vowels = array ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
                                    $ Gantivokal = str_replace ($ vowels, "o", "Learning E-Commerce");
                                    echo $ gantivokal;

                        Example 3:
                                    $ Phrase = "You must learn to courtship, the streets, watching movies
                                    to college. ";
                                    $ Goodness = array ("PHP", "MySQL", "SEO");
                                    $ Ugliness = array ("going out", "the streets", "movies");
                                    $ Kalimatbaru = str_replace ($ evil, $ good, $ sentence);
                                    echo $ kalimatbaru;
                                    STR_IREPLACE str_replace just NOT the same as CASE SENSITIVE.

            3.2.3. Htmlentities
                        Example:
                                    $ Str = "A sign of 'quotation', written by <b> bold </ b>";
                                    / / Output: A sign of 'quotation', written by
                                    <b> bold </ b>
                                    echo htmlentities ($ str);
                                    / / Output: A sign of 'quotation', written by
                                    <b> bold </ b>
                                    echo htmlentities ($ str, ENT_QUOTES);

            3.2.4. Html_entity_decode
                        Example:
                                    $ Orig = "A sign \" quote \ "written by <b> bold </ b>";
                                    $ A = htmlentities ($ orig, ENT_QUOTES);
                                    $ B = html_entity_decode ($ a);
                                    echo $ a; / / A sign of "quotation" written by
                                    <b> bold </ b>
                                    echo $ b; / / A sign of "quotation" written by <b> bold </ b>

            3.2.5. Htmlspecialchars
                        Example:
                                    $ Code = htmlspecialchars ("Fit & Proper <a href='test'>
                                    Test </ a> ", ENT_QUOTES);
                                    echo $ code; / / <a href='test'> Fit & Proper
                                    Test </ a>

3.3. MATHEMATICS (To Be Continued ....)
            3.3.1. ABS
            3.3.2. Ceil
            3.3.3. FLOOR
            3.3.4. MAX
            3.3.5. MIN
            3.3.6. ROUND
            3.3.7. RAND
            3.3.8. FMOD
            3.4. DATE & TIME
            3.5. Sending MAIL

0 komentar

Posting Komentar

Statistik