Exemplo n.º 1
0
 public static function getRegexTags($tags, $include_no_attributes = true, $include_ending = true, $required_attributes = array())
 {
     require_once __DIR__ . '/text.php';
     $tags = NNText::toArray($tags);
     $tags = count($tags) > 1 ? '(?:' . implode('|', $tags) . ')' : $tags['0'];
     $spaces = self::getRegexSpaces();
     $attribs = $spaces . '[^>"]*(?:"[^"]*"[^>"]*)+';
     $required_attributes = NNText::toArray($required_attributes);
     if (!empty($required_attributes)) {
         $attribs = $spaces . '[^>"]*(?:"[^"]*"[^>"]*)*(?:' . implode('|', $required_attributes) . ')\\s*=\\s*(?:"[^"]*"[^>"]*)+';
     }
     if ($include_no_attributes) {
         $attribs = '(?:' . $attribs . ')?';
     }
     if (!$include_ending) {
         return '<' . $tags . $attribs . '>';
     }
     return '<(?:\\/' . $tags . '|' . $tags . $attribs . ')(?:\\/|' . $spaces . ')*>';
 }
Exemplo n.º 2
0
 public static function getRegexTags($tags, $include_no_attributes = true, $include_ending = true, $required_attributes = array())
 {
     require_once __DIR__ . '/text.php';
     $tags = NNText::toArray($tags);
     $tags = count($tags) > 1 ? '(?:' . implode('|', $tags) . ')' : $tags['0'];
     $value = '(?:\\s*=\\s*(?:"[^"]*"|\'[^\']*\'|[a-z0-9-_]+))?';
     $attribs = '(?:\\s+[a-z0-9-_]+' . $value . ')+';
     $required_attributes = NNText::toArray($required_attributes);
     if (!empty($required_attributes)) {
         $attribs = $attribs . '(?:\\s+' . implode('|', $required_attributes) . ')' . $value . $attribs;
     }
     if ($include_no_attributes) {
         $attribs = '\\s*(?:' . $attribs . ')?';
     }
     if (!$include_ending) {
         return '<' . $tags . $attribs . '\\s*>';
     }
     return '<(?:\\/' . $tags . '|' . $tags . $attribs . '\\s*/?)\\s*>';
 }