- preg_replace_callback: documentation ( source)
- trim: documentation ( source)
- strtoupper: documentation ( source)
- strtolower: documentation ( source)
<?php
function smart_uc_words($string)
{
$string = strtolower(trim($string));
// Capitalise any word char preceded by a non-word char other than an apostrophe
$string = preg_replace_callback('/(?<!\w|\')(\w)/', function($m){ return strtoupper($m[1]); }, $string);
// Capitalise any word char which comes between an apostrophe and another word char
$string = preg_replace_callback('/(?<=\')(\w)(?=\w)/', function($m){ return strtoupper($m[1]); }, $string);
return $string;
}
echo smart_uc_words("www.google.com");