function replace(&$string, $regex, $area = 'articles') { list($pre_string, $string, $post_string) = nnText::getContentContainingSearches($string, $this->params->start_tags, null, 200, 500); if ($string == '') { $string = $pre_string . $string . $post_string; return; } if (@preg_match($regex . 'u', $string)) { $regex .= 'u'; } $matches = array(); $protects = array(); if (!nnText::stringContains($string, $this->params->start_tags) || !preg_match_all($regex, $string, $matches, PREG_SET_ORDER)) { $string = $pre_string . $string . $post_string; return; } foreach ($matches as $match) { if ($this->processMatch($string, $match, $area)) { continue; } $protected = $this->params->protect_start . base64_encode($match['0']) . $this->params->protect_end; $string = str_replace($match['0'], $protected, $string); $protects[] = array($match['0'], $protected); } unset($matches); foreach ($protects as $protect) { $string = str_replace($protect['1'], $protect['0'], $string); } $string = $pre_string . $string . $post_string; }