In the event you sort of need multiple delimiters to apply the same action to, you can preg_replace this "second delimiter" enveloping it with your actual delimiter.
A for instance, would be if you wanted to use something like Lee's FormatName function in an input box designed for their full name as this script was only designed to check the last name as if it were the entire string. The problem is that you still want support for double-barreled names and you still want to be able to support the possibility that if the second part of the double-barreled name starts with "mc", that it will still be formatted correctly.
This example does a preg_replace that surrounds the separator with your actual delimiter. This is just a really quick alternative to writing some bigger fancier blah-blah function. If there's a shorter, simpler way to do it, feel free to inform me. (Emphasis on shorter and simpler because that was the whole point of this.) :D
Here's the example. I've removed Lee's comments as not to confuse them with my own.
<?php
function FormatName($name=NULL)
{
if (empty($name))
return false;
$name = strtolower($name);
$name = preg_replace("[\-]", " - ",$name); if (preg_match("/^[a-z]{2,}$/i",$name)) {
$names_array = explode(' ',$name); for ($i = 0; $i < count($names_array); $i++)
{
if (strncmp($names_array[$i],'mc',2) == 0 || ereg('^[oO]\'[a-zA-Z]',$names_array[$i]))
{
$names_array[$i][2] = strtoupper($names_array[$i][2]);
}
$names_array[$i] = ucfirst($names_array[$i]);
}
$name = implode(' ',$names_array);
$name = preg_replace("[ \- ]", "-",$name); return ucwords($name);
}
}
?>