Sunday, January 18, 2015

Lesson 07


ඔන්න ඉතින් යාලුවනේ අදත් මම ඔයාලට තවත් අලුත් පාඩම් මාලාවක් අරගෙන අවා.... 
ටික දවසක් පරක්කු උනාට සමාවෙන්න ඕනේ හොදේ හික් හික් වැඩ ගොඩ ගැහිලා තියෙන්නේ මේ දවස් වල ;)කොහොම උනත් ඉතින් ඔයාල වෙනුවෙන් පොඩි වෙලාවක් හරි අරගෙන අලුත් දෙයක් කියල දෙන එකෙනුත් මර සතුටක් තියෙන්නේ ඔයාලත් අලුතෙන් පොස්ටුවක් එනකම් මග බලාගෙන ඉන්නවා කියල දන්නවා නේ හික් හික්  ඔය මදැයි ඇදබාපුවා ඔන්න එහෙනම් පදමට බහිමු කෙලින් ම

අද මම ඔයාලට කියල දෙන්න යන්නේ php වල String Functions
කියන එක ගැන තමයි. අපි බලමු මේ String Functions වලින් මොන වගේ දේවල් ද කරන්න පුළුවන් කියල... :)
String Functions ගත්තහම ගොඩාක් තියනවා මම ඔයාලට මේකේ වැඩිපුරම use කරන ටිකක් තමයි අද කරන්න යන්නේ ඔයාලට පුළුවන් ඒ හැම Function එකක්ම try කරලා බලන්න.ඔන්න එහෙනම් මේ ටික හොදට බලාගන්නකෝ බය වෙන්න එහෙම එපා හොදේ හික් හික් :D

  • addcslashes — Quote string with slashes in a C style
  • addslashes — Quote string with slashes
  • bin2hex — Convert binary data into hexadecimal representation
  • chop — Alias of rtrim
  • chr — Return a specific character
  • chunk_split — Split a string into smaller chunks
  • convert_cyr_string — Convert from one Cyrillic character set to another
  • convert_uudecode — Decode a uuencoded string
  • convert_uuencode — Uuencode a string
  • count_chars — Return information about characters used in a string
  • crc32 — Calculates the crc32 polynomial of a string
  • crypt — One-way string hashing
  • echo — Output one or more strings
  • explode — Split a string by string
  • fprintf — Write a formatted string to a stream
  • get_html_translation_table — Returns the translation table used by htmlspecialchars and htmlentities
  • hebrev — Convert logical Hebrew text to visual text
  • hebrevc — Convert logical Hebrew text to visual text with newline conversion
  • hex2bin — Decodes a hexadecimally encoded binary string
  • html_entity_decode — Convert all HTML entities to their applicable characters
  • htmlentities — Convert all applicable characters to HTML entities
  • htmlspecialchars_decode — Convert special HTML entities back to characters
  • htmlspecialchars — Convert special characters to HTML entities
  • implode — Join array elements with a string
  • join — Alias of implode
  • lcfirst — Make a string's first character lowercase
  • levenshtein — Calculate Levenshtein distance between two strings
  • localeconv — Get numeric formatting information
  • ltrim — Strip whitespace (or other characters) from the beginning of a string
  • md5_file — Calculates the md5 hash of a given file
  • md5 — Calculate the md5 hash of a string
  • metaphone — Calculate the metaphone key of a string
  • money_format — Formats a number as a currency string
  • nl_langinfo — Query language and locale information
  • nl2br — Inserts HTML line breaks before all newlines in a string
  • number_format — Format a number with grouped thousands
  • ord — Return ASCII value of character
  • parse_str — Parses the string into variables
  • print — Output a string
  • printf — Output a formatted string
  • quoted_printable_decode — Convert a quoted-printable string to an 8 bit string
  • quoted_printable_encode — Convert a 8 bit string to a quoted-printable string
  • quotemeta — Quote meta characters
  • rtrim — Strip whitespace (or other characters) from the end of a string
  • setlocale — Set locale information
  • sha1_file — Calculate the sha1 hash of a file
  • sha1 — Calculate the sha1 hash of a string
  • similar_text — Calculate the similarity between two strings
  • soundex — Calculate the soundex key of a string
  • sprintf — Return a formatted string
  • sscanf — Parses input from a string according to a format
  • str_getcsv — Parse a CSV string into an array
  • str_ireplace — Case-insensitive version of str_replace.
  • str_pad — Pad a string to a certain length with another string
  • str_repeat — Repeat a string
  • str_replace — Replace all occurrences of the search string with the replacement string
  • str_rot13 — Perform the rot13 transform on a string
  • str_shuffle — Randomly shuffles a string
  • str_split — Convert a string to an array
  • str_word_count — Return information about words used in a string
  • strcasecmp — Binary safe case-insensitive string comparison
  • strchr — Alias of strstr
  • strcmp — Binary safe string comparison
  • strcoll — Locale based string comparison
  • strcspn — Find length of initial segment not matching mask
  • strip_tags — Strip HTML and PHP tags from a string
  • stripcslashes — Un-quote string quoted with addcslashes
  • stripos — Find the position of the first occurrence of a case-insensitive substring in a string
  • stripslashes — Un-quotes a quoted string
  • stristr — Case-insensitive strstr
  • strlen — Get string length
  • strnatcasecmp — Case insensitive string comparisons using a "natural order" algorithm
  • strnatcmp — String comparisons using a "natural order" algorithm
  • strncasecmp — Binary safe case-insensitive string comparison of the first n characters
  • strncmp — Binary safe string comparison of the first n characters
  • strpbrk — Search a string for any of a set of characters
  • strpos — Find the position of the first occurrence of a substring in a string
  • strrchr — Find the last occurrence of a character in a string
  • strrev — Reverse a string
  • strripos — Find the position of the last occurrence of a case-insensitive substring in a string
  • strrpos — Find the position of the last occurrence of a substring in a string
  • strspn — Finds the length of the initial segment of a string consisting entirely of characters contained within a given mask.
  • strstr — Find the first occurrence of a string
  • strtok — Tokenize string
  • strtolower — Make a string lowercase
  • strtoupper — Make a string uppercase
  • strtr — Translate characters or replace substrings
  • substr_compare — Binary safe comparison of two strings from an offset, up to length characters
  • substr_count — Count the number of substring occurrences
  • substr_replace — Replace text within a portion of a string
  • substr — Return part of a string
  • trim — Strip whitespace (or other characters) from the beginning and end of a string
  • ucfirst — Make a string's first character uppercase
  • ucwords — Uppercase the first character of each word in a string
  • vfprintf — Write a formatted string to a stream
  • vprintf — Output a formatted string
  • vsprintf — Return a formatted string
  • wordwrap — Wraps a string to a given number of characters


      අම්මෝ කොහොමද නිකම් පිස්සු වගේ නේද හික් හික් :P  
      මේකේ හැම එකකම ලින්කුවක් තියනවා ඕනේ අය ගිහින් example තියනව කරලා බලන්න හික් හික්..... 
       
      අපි දැන් බලමු මේකෙන් නිතරම use වෙන ඒවා මොනවද කියල (නිතරම කිව්වට ඉතින් මේ ඔක්කොම වගේ use වෙනවා හික් හික් )

      මම අද ඔයාලට මෙන්න මේ ටික කියල දෙනවා 
       
    • PHP strlen() function

    • PHP str_word_count() function

    • PHP strrev() function

    • PHP strpos() function

    • PHP str_replace() function

    • PHP strtolower() Function

    • PHP strtoupper() Function

    එහෙනම් ඉතින් මුලින් ම බලමු PHP strlen() function එක ගැන මේක අපි use කරන්නේ string එකක length එක එහෙම නැතිනම් දිග කොචරද කියල මැනගන්න. strlen() function එකෙන් අපි ලියන හැම letter එකක් වගේම Space උත් calculate කරනවා  එහෙනම් කස්ටියම notepad එකක් අරන් මේ code එක ලියල run කරලා බලන්නකෝ වැඩේ ඇත්ත නේද කියල 

    
    <!DOCTYPE html>
    
    <html>
    
    <body>
    
    <?php
    
    echo strlen("I Love PHP Coding!");
    
    ?> 
     
    </body>
    
    </html>
    
    
    

    result එක විදියට ඔයාලට 18 කියල එන්න ඕනේ හික් හික් ඇත්තද කියල බලන්න කම්මැලි කම යන්නත් එක්ක ගැනල බලන්නකෝ space උත් එක්ක හොදේ හික් හික් ;)

    ඊළගට අපි බලමු PHP str_word_count() function එක ගැන
    මේ function එකෙන් කරන්නේ අපි ලියන string එකේ තියන words එහෙමත් නැත්තම් වචන කියල තියනවද කියල calculate කරලා අපිට කියන එකයි බලන්නකෝ ඇත්ත ද මේ කියන්නේ කියල 
    මේක try කරලා බලන්නකෝ කස්ටියත් එක්කම එහෙනම්


    
    <!DOCTYPE html>
    
    <html>
    
    <body>
    
    <?php
    
    echo str_word_count("Welcome to My PHP Blog!");
    
    ?> 
     
    </body>
    
    </html>
    
    
    
     
    result එක විදියට ඔයාලට 5 කියන එක එන්න ඕනේ (ගැනල බලන්නකෝ වචන 5ක් තියනව හික් හික් ... :)


    ඊටපස්සේ අපිට බලන්න තියෙන්නේ PHP strrev() function එක ගැන 
    මේ function එක use කරන්නේ අපි අපි ලියන string එකක් අනිත් පැත්ත හරවල පෙන්නන්න හික් හික් බලන්නකෝ එහෙනම් මේකත් ගහල.

    
    <!DOCTYPE html>
    
    <html>
    
    <body>
    
    <?php
    
    echo strrev("Welcome to My Blog!");
    
    ?> 
     
    </body>
    
    </html>
    
    
    

      Answer එක මෙන්න මෙහෙම එන්න ඕනේ හොදේ හික් හික්....

    "!golB yM ot emocleW"  කොහොමද නිකම් අන්ඩර දෙමළ වගේ නේද හික් හික් ;)
    කස්ටියතව තව ඒවා try කරලා බලන්නකෝ හික්ස්.. :P

    අපි ඊළගට බලමු PHP strpos() function එක ගැන, මේ function එක අපි use කරන්නේ අපිට අපි ලියන string එකේ තියන මොකක්හරි text එකක් search කරන්න ඕනේ නම් අපි මේ function  එක use කරනවා හොදට තේරෙයි මේ code එක කරලා බැලුවහම 

    
    <!DOCTYPE html>
    
    <html>
    
    <body>
    
    <?php
    
    echo strpos("Hello Welcome to My PHP World!", "PHP");
    
    ?> 
     
    </body>
    
    </html>
    
    
    


    result එක විදියට ඔයාලට එන්න ඕනේ 20 කියන එක.
    :O හැබැටම කොහොමද මේ 20 අවේ දැන් ඔයාලට ප්‍රශ්නයක් ඇති 

    එහෙනම් ඉතින් මෙන්න විසදුම හික් හික් ... ;) 
    අපි ලියපු code එකේ string එකට පස්සේ , "PHP" කියල තියනවා ඒ කියන්නේ අපි ලියපු string එකේ  PHP කියල තියන තැන අපිට හොයල දෙන්න කියන එකයි අපිට අන්ස්වෙර් එක විදියට 20 එන්නේ PHP කියල තියෙන්නේ 20 letter එකට පස්සේ නිසයි ගැනල බලන්නකෝ හික් හික්



    ඊළගට අපිට බලන්න තියෙන්නේ  PHP str_replace() function එක ගැන,මේකේ කරන්නේ අපි ලියන string එකේ අපිට කොතන හරි වෙන string එකකින් replace කරන්න ඕනේ නම් මේ function එක use කරලා අපිට පුළුවන් ඒ වැඩේ කරගන්න බලන්නකෝ එහෙනම් මේකත් කරලා 


    <!DOCTYPE html>
    
    <html>
    
    <body>
    
    <?php
    
    echo str_replace("My", "Siripala's", "Welcome to My Blog");
    
    ?> 
     
    </body>
    
    </html>
    
    
    




    result එක විදියට ඔයාලට මෙන්න මෙහෙම එන්න ඕනේ 

     Welcome to Siripala's Blog 

    මේකේ my කියන එක වෙනුවට siripala's කියන එක replace වෙනවා හික් හික් අතල් වැඩේ නේද හික්ස් :P


     අපිට දැන් බලන්න තියෙන්නේ ගොඩාක් ලේසි function දෙකක් මේ දෙකම මම ඔයාලට එකට කියල දෙන්නම්


    PHP strtolower() Function එකෙන් කරන්නේ අපි ලියන string එකේ තියන හැම capital එකක් ම එහෙමත් නැතිනම් (Upper Case letters)  simple වලට එහෙමත් නැතිනම් (Lower Case) වලට හරවනවා

     

    PHP strtoupper() Function එකෙන් කරන්නේ අපි ලියන string එකේ තියන හැම Simple එකක් ම එහෙමත් නැතිනම් (Lower Case letters)  Capital වලට එහෙමත් නැතිනම් ( Upper Case) වලට හරවනවා

     

    බලන්නකෝ මේ example දෙක

    PHP strtolower() Function 

    
    <!DOCTYPE html>
    
    <html>
    
    <body>
    
    <?php
    
    echo strtolower("I LOVE PHP")."</br>";
    
    echo strtolower("welcome to my BLOG!");
    
    ?>
       
    </body>
    
    </html>
    
    
    




    result එක මෙහෙම එන්න ඕනේ 

    "i love php
    welcome to my blog!"


    PHP strtoupper() Function


    
    <!DOCTYPE html>
    
    <html>
    
    <body>
    
    <?php
    
    echo strtoupper("I love PHP")."</br>";
    
    echo strtoupper("welcome to my BLOG!");
    
    ?> 
     
    </body>
    
    </html>
    
    
    


    result එක මෙහෙම එන්න ඕනේ 

    "I LOVE PHP
    WELCOME TO MY BLOG!"
     


    කොහොමද එළකිරි වගේ වැඩ නේද හික්ස් කස්ටියටම හොදට තේරෙන්න ඇති අද අපි කරපු lesson එක නේද ඉතා සරල පාඩමක් තමයි අපි අද කරේ. කස්ටිය ඔය මම දීල තියන අනිත් function ටිකත් හෙමිට නිවාඩු පාඩුවේ ඔක්කොම try කරලා බලන්න ඔයලද ලොකු knowledge එකක් එනවා එතකොට කරලා බලල මොනවා හරි අව්ලක් තියනවනම් මගෙන් අහන්නකො යාලුවනේ 

    එහෙනම් ඉතින් දැන් මට යන්න වෙලාව හරි ගොඩාක් රෑ වෙලත් එක්ක හික් හික් බයෙත් බෑ ලොල් :P

    එහෙනම් කස්ටියම හොදට කියල දීපු පාඩම් ටික කරන්න 
    එහෙනම් ඉතින් හැමෝටම සුබම සුබ රාත්‍රියක් වේවා!!!

    මතක ඇතුව යනකොට කොමෙන්ටුවකුත් දාලම යන්න හොදේ.......

    එහෙනම් අදට මම ගියෝ.............................
    :) හික් හික්










    No comments: