private function parse_attributes()
{
$attr = array();
$name = '';
$this->skip_whitespace();
// read attribute name
while ($name = $this->up_to_chr(self::$CHR_ATTRNAME_END . self::$CHR_TAG_END . self::$CHR_WHITESPACE)) {
$name = strtolower(rtrim($name, self::$CHR_TAG_END_TRIM));
// skip any whitespace
$this->skip_whitespace();
// first non-ws char
$char = $this->get();
if ($char == '=') {
// attribute value follows
$this->skip_whitespace();
$char = $this->get();
if ($char == '"') {
// double-quoted
$value = $this->up_to_str('"');
$this->inc();
} elseif ($char == '\'') {
// single-quoted
$value = $this->up_to_str('\'');
$this->inc();
} else {
// bad, bad, bad
$this->dec();
$value = $this->up_to_chr(self::$CHR_WHITESPACE . '>');
}
} elseif ($char !== null) {
// TODO HTMLParser should handle #IMPLIED attrs
$value = null;
$this->dec();
} else {
// default
$value = null;
}
// store that attribute only if it's not empty
if ($name) {
$attr[$name] = $value;
}
$this->skip_whitespace();
}
return $attr;
}