3v4l.org

run code in 300+ PHP versions simultaneously
<?phpfunction strposGetContext($haystack, $needle, $context = 10, $ignoreChars = "-\n /") { $ignore = str_split($ignoreChars); $needle = str_replace($ignore, '', $needle); $cleanedHaystack = str_replace($ignore, '', $haystack); $position = 0; $results = []; while (($foundStart = stripos($cleanedHaystack, $needle, $position)) !== false) { $foundEnd = $foundStart + strlen($needle); $position = $foundEnd; $dirtyHaystackPosition = 0; while ($dirtyHaystackPosition < $foundEnd && $dirtyHaystackPosition < strlen($haystack)) { if (in_array($haystack[$dirtyHaystackPosition], $ignore)) { if ($dirtyHaystackPosition <= $foundStart) { $foundStart++; } $foundEnd++; } $dirtyHaystackPosition++; } $results[] = substr( $haystack, $foundStart - $context < 0 ? 0 : $foundStart - $context, $found_end - $found_start + $context ); } return $results;}$text = 'This is some text target-text and we have some string target text you are looking for!!!! target----text WOO';var_dump(strposGetContext($text, 'targettext'));
Output for git.master, git.master_jit, rfc.property-hooks
<?phpfunction strposGetContext($haystack, $needle, $context = 10, $ignoreChars = "-\n /") { $ignore = str_split($ignoreChars); $needle = str_replace($ignore, '', $needle); $cleanedHaystack = str_replace($ignore, '', $haystack); $position = 0; $results = []; while (($foundStart = stripos($cleanedHaystack, $needle, $position)) !== false) { $foundEnd = $foundStart + strlen($needle); $position = $foundEnd; $dirtyHaystackPosition = 0; while ($dirtyHaystackPosition < $foundEnd && $dirtyHaystackPosition < strlen($haystack)) { if (in_array($haystack[$dirtyHaystackPosition], $ignore)) { if ($dirtyHaystackPosition <= $foundStart) { $foundStart++; } $foundEnd++; } $dirtyHaystackPosition++; } $results[] = substr( $haystack, $foundStart - $context < 0 ? 0 : $foundStart - $context, $found_end - $found_start + $context ); } return $results;}$text = 'This is some text target-text and we have some string target text you are looking for!!!! target----text WOO';var_dump(strposGetContext($text, 'targettext'));

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:
49.99 ms | 403 KiB | 8 Q