Parse attributes in an HTML fragment and return them as a list of lists.
Each element of that list is either a single element, if the attribute had no value, or
a two-tuple, with the first element being the name of the attribute and the second being
the value. The attribute names are all converted to lowercase.
If you don't really care what happens when the same attribute is present twice, you can also use the
attribute_array argument, and the attributes will be
set there. For attributes without any value, we'll use the empty string.
Example:
set html {<tag foo = bar baz greble=""hello you sucker"" foo='blah' Heres = ' something for you to = "consider" '>}
set pos 5 ; # the 'f' in the first 'foo'
set attribute_list [ad_parse_html_attributes_upvar -attribute_array attribute_array html pos]
attribute_list will contain the following:
{foo bar} baz {greble {"hello you sucker"}} {foo blah} {heres { something for you to = "consider" }}
attribute_array will contain:
attribute_array(foo)='blah'
attribute_array(greble)='"hello you sucker"'
attribute_array(baz)=''
attribute_array(heres)=' something for you to = "consider" '
Won't alter the string passed in .. promise!
We will modify pos_var. Pos_var should point to the first character inside the tag,
after the tag name (we don't care if you let if there's some whitespace before the first attribute)
- Switches:
- -attribute_array (optional)
- This is an alternate way of returning the attributes, if you don't care
about what happens when the same attribute name is defined twice.
- Parameters:
-
html_varname - the name of the variable holding the HTML
fragment. We promise that we won't change the contents of this
variable.
pos_varname - the name of the variable holding the position
within the html_varname string from which we should
start. This should point to a character inside the tag, just after
the tag name, and before the first attribute. Note, that we will modify this variable.
When this proc is done, this variable will point to the tag-closing >.
Example:
if the tag is <img src="foo">, pos_varname should point to either the space between
img and src, or the s in src.
- Returns:
- A list of list holding the attribute names and
values. Each element of that list is either a single element, if the
attribute had no value, or
a two-tuple, with the first element being the name of the attribute and the second being
the value. The attribute names are all converted to lowercase.
- Author:
- Lars Pind <lars@pinds.com>
- Created:
- November 10, 2000