$line = str_replace(' ', '', trim($line));
$line = trim(preg_replace('/\s{2,}/', ' ', $line))

Заменить данные

                                    $arItem['BODY_FORMATED'] = str_replace(
                                        array("<b>", "</b>"),
                                        array("<mark>", "</mark>"),
                                        $arItem['BODY_FORMATED']
                                    );