3v4l.org

run code in 300+ PHP versions simultaneously
<?php $chunk = 'This is a very large text line I have ever seen in my life and I love it.'; $searchfor = 'I have'; $pattern = preg_quote($searchfor, '/'); $pattern = "/^.*?(.{1,10}$pattern.{1,10}).*$/m"; if(preg_match_all($pattern, $chunk, $matches)){ echo "Found matches:\n"; echo implode("\n", $matches[1]) . "\n"; } $searchfor = 'a very'; $pattern = preg_quote($searchfor, '/'); $pattern = "/^.*?(.{1,10}$pattern.{1,10}).*$/m"; if(preg_match_all($pattern, $chunk, $matches)){ echo "Found matches:\n"; echo implode("\n", $matches[1]) . "\n"; } $searchfor = 'and I'; $pattern = preg_quote($searchfor, '/'); $pattern = "/^.*?(.{1,10}$pattern.{1,10}).*$/m"; if(preg_match_all($pattern, $chunk, $matches)){ echo "Found matches:\n"; echo implode("\n", $matches[1]) . "\n"; }
Output for 5.6.38, 7.1.0 - 7.1.23, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Found matches: text line I have ever seen Found matches: This is a very large tex Found matches: n my life and I love it.

preferences:
151.44 ms | 408 KiB | 5 Q