3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_between($string, $start, $end, $trim = true, $greedy = false) { $pattern = '/' . preg_quote($start) . '(.*'; if (!$greedy) $pattern .= '?'; $pattern .= ')' . preg_quote($end) . '/'; preg_match($pattern, $string, $matches); $string = $matches[0]; if ($trim) { $string = substr($string, strlen($start)); $string = substr($string, 0, -strlen($start) + 1); } return $string; } function find_between2($string, $start, $end, $trim = true, $greedy = false) { $stringOut = ''; $pattern = '/'.preg_quote($start).'(.*'; if (!$greedy) $pattern .= '?'; $pattern .= ')'.preg_quote($end).'/'; preg_match($pattern, $string, $matches); if (count($matches)>1) { if ($trim) { $stringOut = $matches[1]; } else { $stringOut = $matches[0]; } } return ($stringOut==='')?false:$stringOut; } $string = 'The quick brown fox jumps over the lazy (not jumping) dog'; $start = 'quick'; $end = 'jump'; var_dump(find_between($string, $start, $end)); var_dump(find_between2($string, $start, $end));
Output for git.master, git.master_jit, rfc.property-hooks
string(11) " brown fox " string(11) " brown fox "

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:
54.68 ms | 401 KiB | 8 Q