Skip to content

Instantly share code, notes, and snippets.

@Vondelphia
Vondelphia / replace-cars-with-semi.txt
Last active October 10, 2025 16:42
Replace all instances of a specific word and match original case
// Replace all instances of "car" with "semi" across entire website (case-preserving)
function replace_car_with_semi($content) {
return preg_replace_callback('/\bcar\b/i', function($match) {
// Preserve original case pattern
if (ctype_upper($match[0])) {
return 'SEMI'; // CAR -> SEMI
} elseif (ctype_upper($match[0][0])) {
return 'Semi'; // Car -> Semi
}
return 'semi'; // car -> semi