How to match HTML tags with multiple attributes with regular matches

Source: Internet
Author: User
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 "";
}



  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.