Is it possible to write a pattern to match a html tag with indeterminate number of attributes and return these attributes as array with attribute name as key and value as value???
e.g.: <user_data name="Ben" email="ben@ben" ... /> will return $user_data = array('name'=>'Ben', 'email'=>'ben@ben');
$tag = '<user_data name="Ben" email="ben@ben" />';
preg_match('/<user_data\s+((.*)=(.*))*?\s*\/>/', $tag, $attribs);
echo '<pre>';
print_r($attribs);
echo '</pre>';
I have tried the code above, but it's not working as intended.
If it'is impossible to achieve above array using only a single pattern, the array below also is accepted, thus I can use it to build an array as intended.
Array
(
[0] => 'name'
[1] => 'Ben'
[2] => 'email'
[3] => 'ben@ben'
)
Another any approach are welcome too...