dev
dev

Reputation: 439

php strtok function not getting this example

What will be the output of following PHP code:

<?php

echo strtok("Hello world!","kHlleo");

?>

answer is w

can any one explain how it works to output w ? i know strtok tokenise the string, but not understanding this particular question.

Upvotes: 0

Views: 84

Answers (1)

Niels
Niels

Reputation: 101

It basically returns a list with letters that are not filtered. You filter the letters "kHlleo", out of "Hello world!", leaving w, r and d!.

$tok = strtok("Hello world!", "kHlleo");

while ($tok !== false) {
echo "Word=$tok<br />";
$tok = strtok("kHlleo");
}

Upvotes: 1

Related Questions