<?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);
You have javascript disabled. You will not be able to edit any code.