<?php

    $str = 'he said "hello WORLD"';
    $str = strtolower($str); // first lowercase everything
    echo preg_replace('/\b([a-z])/e', 'strtoupper(\'$1\')', $str);

    echo "\n";

    $str = 'he said "καλημέρα ΚΌΣΜΕ"'; // this has to be in UTF-8
    $str = mb_convert_case($str, MB_CASE_LOWER, 'UTF-8');
    echo preg_replace('/(?<!\p{L})(\p{Ll})/eu',
                      'mb_convert_case(\'$1\', MB_CASE_UPPER, \'UTF-8\')',
                      $str);
