Replaced str_replace with preg_replace for consistency