3v4l.org

run code in 300+ PHP versions simultaneously
<?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");

preferences:
50.88 ms | 402 KiB | 5 Q