(.*)<\/\s*' . $tag . '\s*>/Usi', $content, $ucb) != 0) { $mark = md5($ucb[1] . $num++ . microtime()); $ncc[$mark] = $ucb[1]; $content = str_replace($ucb[1], $mark, $content); } } // Compact the text $content = str_replace('> <', '><', preg_replace('/\s+/', ' ', $content)); // Insert back all saved tags content $ncc = array_reverse($ncc); foreach ($ncc as $mark => $text) { $content = str_replace($mark, $text, $content); } return $content; }