3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ (object) ['content' => 'one, two three four five, six seven'], (object) ['content' => 'foo'], (object) ['content' => 'fee fi, foe, fum, gimme those beans dude'], (object) ['content' => 'one a b c, two d e f g, three h, four i j, five k l m, six n, seven o p, eight q, nine r s t, ten u v w x, eleven y and z'], ]; foreach ($tests as $metakw) { preg_match_all( '/(?:^|, *\K)[^, ]+(?: *[^, ]+){0,2}/', $metakw->content, $matches, ); var_dump( array_slice($matches[0], 0, 10) ); echo "\n---\n"; }
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array(3) { [0]=> string(3) "one" [1]=> string(14) "two three four" [2]=> string(9) "six seven" } --- array(1) { [0]=> string(3) "foo" } --- array(4) { [0]=> string(6) "fee fi" [1]=> string(3) "foe" [2]=> string(3) "fum" [3]=> string(17) "gimme those beans" } --- array(10) { [0]=> string(7) "one a b" [1]=> string(7) "two d e" [2]=> string(7) "three h" [3]=> string(8) "four i j" [4]=> string(8) "five k l" [5]=> string(5) "six n" [6]=> string(9) "seven o p" [7]=> string(7) "eight q" [8]=> string(8) "nine r s" [9]=> string(7) "ten u v" } ---

preferences:
62.95 ms | 1069 KiB | 4 Q