The explode() function is used to split a string into an array.
Syntax: explode(separator,string[,limit]);
separator – the character or characters at which the string should be split.
string – the input string
limit – the maximum number of array elements you allow the string to be split into.
Example inputs:
1.
$str= "This is a simple program";
print_r(explode(" ",$str));
2.
$str= "This is a simple program";
print_r(explode(" ",$str,3));
Carefully note the difference in output between the two examples.
Example outputs:
1.
Array ( [0] => This [1] => is [2] => a [3] => simple [4] => program )
2.
Array ( [0] => This [1] => is [2] => a simple program )
Showing posts with label string functions in php. Show all posts
Showing posts with label string functions in php. Show all posts
Monday, September 29, 2008
Saturday, September 13, 2008
The strrev() function
This function is used to reverse any given string.
Syntax: strrev(string);
Example inputs:
$str1= "A simple PHP program";
echo $str1."
";
$str2 = strrev($str1);
echo $str2."
";
echo $str1."
";
echo strrev($str1);
Syntax: strrev(string);
Example inputs:
$str1= "A simple PHP program";
echo $str1."
";
$str2 = strrev($str1);
echo $str2."
";
echo $str1."
";
echo strrev($str1);
Subscribe to:
Posts (Atom)