Add unicode support to preg_replace and kill redundant whitespace removal

The 'u' flag for preg_replace means the pattern and subject strings are treated as UTF-8.

The trim was doing duplicate removal of whitespace.