How to match HTML tags with multiple attributes with regular matches
All kinds of labels, no rules, mostly or the order of attributes is unclear
Like this but there are several kinds of attribute order, but also to get the ID href class three attribute values, stored in \1 \2 \3 (I use the preg_replace, because the entire label to replace the specified format)
Thought for a long time do not know how to write a look at the expert to help
I also want to use]*) > match to the post-processing properties, and then replace it with Str_replace, but such repeated searches may lead to too much resource overhead. What can be done to achieve the above requirements? Man help.
------Solution--------------------
Recommend you to learn the use of phpquery, from this collection does not need to use regular
------Solution--------------------
This post was last edited by xuzuning on 2014-02-27 09:09:12
$s =<<< TXT
TXT;
echo preg_replace_callback ('//i ', ' foo ', $s);
function foo ($r) {
Preg_match_all ('/(\w+) = "(. +?)" /', $r [0], $t);
$t = Array_combine ($t [1], $t [2]);
Ksort ($t);
$s = ";
foreach ($t as $k + $v) $s. = "$k = ' $v '";
Return "";
}