- preg_replace_callback: documentation ( source)
- strtoupper: documentation ( source)
- strtolower: documentation ( source)
<?php
$str = "yOu aRe KiNd";
echo preg_replace_callback('/[a-z](?![a-z])/', function ($m) { return strtoupper($m[0]); }, strtolower($str));