3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "some text here [baz] and here [you|him|her|foo|bar|baz|foo|option|test] and even here [another]."; $pattern = (function () use ($string) { $array = []; for ($i = 0; $i <= substr_count($string, "|"); $i++) { $array[] = $i == 0 ? '([^][|]+)' : '([^][|]+)?'; } return implode("\|?", $array); })(); preg_match_all("~\[$pattern]~", $string, $matches, PREG_SET_ORDER); var_dump($matches);
Output for git.master, git.master_jit, rfc.property-hooks
array(3) { [0]=> array(2) { [0]=> string(5) "[baz]" [1]=> string(3) "baz" } [1]=> array(10) { [0]=> string(41) "[you|him|her|foo|bar|baz|foo|option|test]" [1]=> string(3) "you" [2]=> string(3) "him" [3]=> string(3) "her" [4]=> string(3) "foo" [5]=> string(3) "bar" [6]=> string(3) "baz" [7]=> string(3) "foo" [8]=> string(6) "option" [9]=> string(4) "test" } [2]=> array(2) { [0]=> string(9) "[another]" [1]=> string(7) "another" } }

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:
132.26 ms | 407 KiB | 5 Q