rewriting utf8 encoding function. preg_replace is safer that splitting into