strtok funksiýasy

strtok funksiýasy, setiri görkezilen bölüjiler ulanyp yzygiderli tokenlere (böleklere) bölýär. Funksiýanyň ilkinji çaýyrylmasy setiri we bölüjileri kabul edýär, soňky çaýyryşlar bolsa, ähli tokenler gaýtarylýança şol bir setir bilen işleýär. Tokenler gutaranda, funksiýa false gaýtarýar.

Sintaksis

phpstrtok(string, token);

Mysal

Setiri bosluklar boyunça bölýäris:

php<?php
  $string = "Hello world! How are you?";
  $token = strtok($string, " ");
  
  while ($token !== false) {
    echo $token . "\n";
    $token = strtok(" ");
  }
?>

Kody ýerine ýetirmegiň netijesi:

phpHello
world!
How
are
you?

Mysal

Setiri birnäçe bölüji boyunça bölýäris:

php<?php
  $string = "one,two-three.four";
  $token = strtok($string, ",-.");
  
  while ($token !== false) {
    echo $token . "\n";
    $token = strtok(",-.");
  }
?>

Kody ýerine ýetirmegiň netijesi:

phpone
two
three
four

Şeýle-de serediň

  • explode funksiýasyny,
    setiri bölüji boyunça bölýän
  • implode funksiýasyny,
    massiwleri setir bilen birleşdirýän