3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = 'Here are @user:123 and @user:456 mentions'; $contextSize = 5; $pattern = '~ @user:[0-9]+ \s* (*:mention) | \S+ \s* ~x'; $results = []; if (preg_match_all($pattern, $text, $matches)) { foreach ($matches['MARK'] as $k => $v) { $beforeIndex = max(0, $k - $contextSize); $beforeSize = $k - $beforeIndex; $afterIndex = $k + 1; $results[] = [ 'before' => join(array_slice($matches[0], $beforeIndex, $beforeSize)), 'mention' => $matches[0][$k], 'after' => join(array_slice($matches[0], $afterIndex, $contextSize)) ]; } } print_r($results);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [before] => Here are [mention] => @user:123 [after] => and @user:456 mentions ) [1] => Array ( [before] => Here are @user:123 and [mention] => @user:456 [after] => mentions ) )

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:
77.9 ms | 406 KiB | 5 Q