3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 hhvm-3.10.0

Process exited with code 153.
Output for 5.4.0 - 5.4.32
<?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'));