Sunday, 27 July 2014

lcfirst(), ucfirst() and ucwords() in php

lcfirst() Function:

                                    lcfirst() function that is use to convert the first character of string in lowercase letter. It is also very useful function in php many example of this function in php one of them comparison the value from data base.

Syntax:

          lcfirst(string);

Example:

<?php
$str=”HELLO PHP”;
echo lcfirst($str);
?>

Output:

         hELLO PHP

ucfirst() Function:

                                    ucfirst() function that is use to convert the first character of string in uppercase letter. It is also very useful function in php many example of this function in php one of them comparison the value from data base.

Syntax:

          ucfirst(string);

Example:

<?php
$str=”hello PHP”;
echo ucfirst($str);
?>

Output:

         Hello PHP

ucwords() Function:

                                    ucwords() function that is use to convert the first character of each word in string to uppercase letter. It is also very useful function in php many example of this function in php one of them comparison the value from data base.

Syntax:

          ucwords(string);

Example:

<?php
$str=”hello php”;
echo ucwords($str);
?>

Output:


         Hello Php


strtolower() and strtoupper() in php

strtolower() Function:

                                    strtolower() function that is use to convert the string in lowercase letters. It is also very useful function in php many example of this function in php one of them comparison the value from data base.

Syntax:

          strtolower(string);

Example:

<?php
$str=”HELLO PHP”;
echo strtolower($str);
?>

Output:

         hello php

strtoupper() Function:

                                    strtoupper() function that is use to convert the string in uppercase letters. It is also very useful function in php many example of this function in php one of them comparison the value from data base.

Syntax:

          strtoupper(string);

Example:

<?php
$str=”hello php”;
echo strtoupper($str);
?>

Output:


         HELLO PHP


strlen() in php

strlen() Function:

                             strlen() function that is use to find the length of string. It is more commonly use function in php. More commonly use of this function is get the length of password that user entered.

Syntax:

           Strlen(string);

Example:

<?php
$str=”hello php”;
echo strlen($str);
?>

Output:

                         9


Note :whitespaces are also include in string “hello php”.


strcmp() in php

strcmp() Function:

                             strcmp() function is use to compare the two string. The function return zero if two string are equal. If string1 greater than string2 then it return positive value or If string1 less than string2 then it return negative value.

Syntax:

          Strcmp(string1,string2);

Example:

<?php
echo strcmp(“php”,”php”);
echo strcmp(“php hello”,”php”);
echo strcmp(“php”,”php hello”);
?>

Output:                                        


          0 6 -6


str_split() in php

str_split() :

                               str_split() function that is use to divide the string into array

syntax:

str_split(string, number of character);
number of character: its optional argument it takes numeric value greater than zero its by default value is one. Its value mean how many character will be stored in the indexes of arrays.

Example:

<?php
$str=”php”;
Print_r(str_split($str));
print_r(str_split($str,2));
?>

Output:

          Array ( [0] => p [1] => h [2] => p )
          Array ( [0] => ph [1] => p )
               


str_repeat() in php

str_repeat() Function:

                                                          str_repeate() function is use to repeat a string specific numbers of times as user wants.

Syntax:

                 str_repeat(string,counter);counter: 
                  it takes the numeric value greater than zero which times you want to repeat the                             string.

Example:

 <?php                                                                                                                                                      
$str=”hello php”;                                                                                                                                       echo str_repeat($str,3);                                                                                                                          
?>                                                                                                                                                              

Output:

          hello phphello php hello php



st_ireplace() in php

 str_ireplace() Function:

                                       str_ireplace() function that is use to replace some character of string from other character it is case insensitive if we use str_replace() function the it have the same functionality but it is case sensitive.

Syntax:

          str_ireplace(finding character, replacement character, string, count);finding character(optional) :find the character that we want to replace
replacement character(optional): the specific character that replace form finding value
count(optional): it count that how many time character is replace

Example:

 <?php 
$str= “hello php”;
echo str_ireplace(“php”,”umer”,$str);
?>

  Output:

               hello umer