Tuesday, September 23, 2008

The strtok() function

This function could be used to split a string into smaller strings.

Syntax: strtok(string,split);

split – the split character
Example input:
$str1="This is a simple PHP program";
echo $str1;
echo "
";
echo $str2 = strtok($str1," ");
echo "
";
echo strtok(" ");
echo "
";
echo strtok(" ");
Example output:
This is a simple PHP program This is a
A good look at the example and you will realize that the string is specified only for the first time strtok() is called. For subsequent calls, the string need not be mentioned as the function keeps track of the current string.

No comments: