Exemplo n.º 1
0
 function replace(&$string, $area = 'articles')
 {
     list($pre_string, $string, $post_string) = NNText::getContentContainingSearches($string, $this->params->start_tags, null, 200, 500);
     if ($string == '' || !NNText::stringContains($string, $this->params->start_tags)) {
         $string = $pre_string . $string . $post_string;
         return;
     }
     $regex = $this->params->regex;
     if (@preg_match($regex . 'u', $string)) {
         $regex .= 'u';
     }
     $matches = array();
     $protects = array();
     if (!preg_match_all($regex, $string, $matches, PREG_SET_ORDER)) {
         $string = $pre_string . $string . $post_string;
         return;
     }
     foreach ($matches as $match) {
         if (strpos($string, $match['0']) === false) {
             continue;
         }
         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) {
         if (strpos($string, $protect['1']) === false) {
             continue;
         }
         $string = str_replace($protect['1'], $protect['0'], $string);
     }
     $string = $pre_string . $string . $post_string;
 }