Ejemplo n.º 1
0
 /**
  * Combine duplicate <p> tags
  * input: <p class="aaa" a="1"><!-- ... --><p class="bbb" b="2">
  * output: <p class="aaa bbb" a="1" b="2"><!-- ... -->
  */
 public static function combinePTags(&$string)
 {
     if (empty($string)) {
         return;
     }
     $p_start_tag = '<p(?: [^>]*)?>';
     $optional_tags = '\\s*(?:<\\!-- [^>]*-->|&nbsp;|&\\#160;)*\\s*';
     if (!preg_match_all('#(' . $p_start_tag . ')(' . $optional_tags . ')(' . $p_start_tag . ')#si', $string, $tags, PREG_SET_ORDER) > 0) {
         return;
     }
     foreach ($tags as $tag) {
         $string = str_replace($tag['0'], $tag['2'] . NNText::combineTags($tag['1'], $tag['3']), $string);
     }
 }