strtokPodręcznik PHPPoprzedniNastępnystrtok (PHP 3, PHP 4 >= 4.0.0)strtok -- Tokenize stringDescriptionstring strtok (string arg1, string arg2)
strtok() is used to tokenize a string. That
is, if you have a string like "This is an example string" you
could tokenize this string into its individual words by using the
space character as the token.
Przykład 1. strtok() example$string = "This is an example string";
$tok = strtok($string," ");
while ($tok) {
echo "Word=$tok<br>";
$tok = strtok(" ");
}
Note that only the first call to strtok uses the string argument.
Every subsequent call to strtok only needs the token to use, as
it keeps track of where it is in the current string. To start
over, or to tokenize a new string you simply call strtok with the
string argument again to initialize it. Note that you may put
multiple tokens in the token parameter. The string will be
tokenized when any one of the characters in the argument are
found.
The behavior when an empty part was found changed with PHP 4.1.0. The old
behavior returned an empty string, while the new, correct, behavior
simply skips the part of the string:
Przykład 2. Old strtok() behavior$first_token = strtok('/something', '/');
$second_token = strtok('/');
var_dump ($first_token, $second_token);
/* Output:
string(0) ""
string(9) "something"
*/
Przykład 3. New strtok() behavior$first_token = strtok('/something', '/');
$second_token = strtok('/');
var_dump ($first_token, $second_token);
/* Output:
string(9) "something"
bool(false)
*/
Also be careful that your tokens may be equal to "0". This
evaluates to FALSE in conditional expressions.
See also split() and
explode().
PoprzedniSpis treściNastępnystrstrPoczątek rozdziałustrtolower
Wyszukiwarka
Podobne podstrony:
function strtokfunction strtokfunction fdf next field namefunction ccvs voidfunction mysql errorfunction mcal event set endfunction mcrypt cbcFunctional Origins of Religious Concepts Ontological and Strategic Selection in Evolved Mindsfunction domnode get contentfunction mcrypt module get algo key sizefunction pdf execute imagewięcej podobnych podstron