3v4l.org

run code in 300+ PHP versions simultaneously
<?php function remove_after($needle, $haystack, $removeNeedle = false) { $needle = preg_quote($needle) . ($removeNeedle ? '' : '\K'); return preg_replace("#.*\K$needle.*#s", '', $haystack); } var_dump(remove_after("cheese", "The cheese is good and the cheese is yummy")); var_dump(remove_after("cheese", "The cheese is good and the cheese is yummy", true));

preferences:
26.51 ms | 406 KiB | 5 Q