strtok funksiyası
strtok funksiyası sətri göstərilən ayırıcılardan istifadə edərək ardıcıl olaraq tokenlara (hissələrə) bölür. Funksiyanın ilk çağırışı sətri və ayırıcıları qəbul edir, sonrakı çağırışlar bütün tokenlar qaytarılana qədər eyni sətirlə işləyir. Tokenlar bitdikdə, funksiya false qaytarır.
Sintaksis
phpstrtok(string, token);
Nümunə
Sətri boşluqlara görə bölək:
php<?php
$string = "Hello world! How are you?";
$token = strtok($string, " ");
while ($token !== false) {
echo $token . "\n";
$token = strtok(" ");
}
?>
Kodun icrasının nəticəsi:
phpHello
world!
How
are
you?
Nümunə
Sətri bir neçə ayırıcıya görə bölək:
php<?php
$string = "one,two-three.four";
$token = strtok($string, ",-.");
while ($token !== false) {
echo $token . "\n";
$token = strtok(",-.");
}
?>
Kodun icrasının nəticəsi:
phpone
two
three
four