Voting

: min(seven, one)?
(Example: nine)

The Note You're Voting On

kendsnyder at gmail dot com
17 years ago
Here is a function to capitalize a last name, accounting for hyphens, apostrophes, "Mc" and "Mac":

<?php
function CapitalizeLastName($name) {
$name = strtolower($name);
$name = join("'", array_map('ucwords', explode("'", $name)));
$name = join("-", array_map('ucwords', explode("-", $name)));
$name = join("Mac", array_map('ucwords', explode("Mac", $name)));
$name = join("Mc", array_map('ucwords', explode("Mc", $name)));
return
$name;
}
?>

I speed tested it against functions that used preg_replace() with an "e" modifier, preg_replace_callback(), and a character-by-character parsing. Unexpectedly, this function using join(), array_map() and explode() was fastest.

<< Back to user notes page

To Top