3v4l.org

run code in 300+ PHP versions simultaneously
<?php function modern_strtok(string $string, string $delim): \Generator { $pos = 0; while (true) { $pos += \strspn($string, $delim, $pos); $len = \strcspn($string, $delim, $pos); if (!$len) return; $delim = (yield \substr($string, $pos, $len)) ?? $delim; $pos += $len; } } $string = ' -- This -- is an example -string '; $delim = ' -'; foreach (modern_strtok($string, $delim) as $tok) { var_dump($tok); } echo "************\n"; // changing $delim mid-course for ($g = modern_strtok($string, $delim); $g->valid(); $g->send($delim)) { var_dump($g->current()); $delim = ' '; }
Output for git.master, git.master_jit, rfc.property-hooks
string(4) "This" string(2) "is" string(2) "an" string(7) "example" string(6) "string" ************ string(4) "This" string(2) "--" string(2) "is" string(2) "an" string(7) "example" string(7) "-string"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.55 ms | 405 KiB | 5 Q