Sunday, September 16, 2007

php strtok( ) function

Hi, its been a lot of time I have been working in php. Although i had been using this function for a long time I was quite unaware about its importance. This made me put a post about this nice function.

strtok() splits a string into smaller strings usually called as tokens, with each token being delimited by any character from token. That is, if you have a string like "This is vijithbk" you could tokenize this string into its small words by using the space character as the token.


$string = "This is vijith";

$tok = strtok($string, " ");

while (
$tok !== false)
{
echo
"Word=$tok \n";
$tok = strtok(" ");
}
//Output

Word=This Word=is Word=vijith

1 comment:

SANA said...

Hi, this post helped me a lot. Also please can you mail me the code to search email from a file. I am a newbie in php. thanks in advance..

Post a Comment