Thursday, 28 July 2011

some basic string functions in PHP.

hi,

The php functions i have learnt today are...

1.strlen(string or $variable) -- tells the length of the string.

$var = 'hello';
echo strlen($var);

o/p: 5

2. strrev(string or $variable) -- reverses the given string.

$var = 'hello';
echo strrev($var);

o/p: olleh

3. strtolower(string or $varible) -- makes the entire string into lower case.

$var = 'HEllO';
echo strtolower($var);

o/p: hello

4. strtolower(string or $varible) -- makes the entire string into upper case.

$var = 'hello';
echo strtoupper($var);

o/p: HELLO

5. ucfirst(string or $varible) -- makes the first character of the string into upper case.

$var = 'hello';
echo ucfirst($var);

o/p: Hello

6. ucwords(string or $varible) -- makes the first character of the string into upper case.

$var = 'hello there';
echo ucwords($var);

o/p: Hello There

7. explode(delimiter,str,limit(optional)) -- splits the given string on every delimiter.

$fullname = 'bullet paandi';
$name = explode(" ",$fullname);
echo "firstname = ".$name[0];
echo "lastname = ".$name[1];

o/p: firstname = vijay lastname = kumar

8. str_split(str,split_length(optional)) -- splits the given string accordind to split length.

$fullname = 'bullet paandi';
$name = str_split($fullname,3);
echo " ".$name[0];
echo " ",$name[1];
echo " ".$name[2];
echo " ".$name[3];

o/p: bul let pa and i

No comments:

Post a Comment