3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "my cat is going to the vet"; $ignore = array("my", "is", "to", "the"); $pattern = "~^[a-z]+|\b(?|" . implode("|", $ignore) . ")\b(*SKIP)(*FAIL)|[a-z]+~"; echo "$pattern\n---\n"; echo preg_replace_callback($pattern, function($m) {return ucfirst($m[0]);}, $string);

preferences:
24.45 ms | 406 KiB | 5 Q