예제 #1
0
 public static function getRegexTags($tags, $include_no_attributes = true, $include_ending = true, $required_attributes = array())
 {
     require_once __DIR__ . '/text.php';
     $tags = RLText::toArray($tags);
     $tags = count($tags) > 1 ? '(?:' . implode('|', $tags) . ')' : $tags['0'];
     $value = '(?:\\s*=\\s*(?:"[^"]*"|\'[^\']*\'|[a-z0-9-_]+))?';
     $attributes = '(?:\\s+[a-z0-9-_]+' . $value . ')+';
     $required_attributes = RLText::toArray($required_attributes);
     if (!empty($required_attributes)) {
         $attributes = '(?:' . $attributes . ')?' . '(?:\\s+' . implode('|', $required_attributes) . ')' . $value . '(?:' . $attributes . ')?';
     }
     if ($include_no_attributes) {
         $attributes = '\\s*(?:' . $attributes . ')?';
     }
     if (!$include_ending) {
         return '<' . $tags . $attributes . '\\s*/?>';
     }
     return '<(?:\\/' . $tags . '|' . $tags . $attributes . '\\s*/?)\\s*/?>';
 }