[Share] use regular expressions to analyze/extract XML/XHTML tag attributes and view the code directly. For more information, see. PHPcode & lt ;? Php # author: selfimip # blog: http://blog.csdn.net/lgg201#mail:lgg860911@yahoo.c [share] Regular Expression Analysis/extract XML/XHTML label attributes
Let's look at the code directly. please kindly advise if you have any shortcomings ..
PHP code
(?> \ W +) # tag name (? P # single attribute sub-group (?> \ S +) # front blank (? P \ w +) # attribute name = # value assignment symbol (? P
(? P
') | (? P
") # Read the quotation marks (? P # value processing sub-group (? : # Decomposition of values: 1) part of an even number of escape characters; 2) single escape character + quotation marks or non-currently used quotation marks (? P
(?> (? : \) *) # Consumes an even number of escape characters (? P
# Processing of non-escape characters \\\\(? P = quote) | (? (5) [^ '] | [^ "]) # Here, a branch is used. one side is an escape character + quotation mark, and the other side is a condition matching non-current quotation mark character )) * # Group the value for 0 or multiple times )(? P = quote) # enclosed by quotation marks) * # Duplicate attributes \ s * # trailing blank \/?> # Tag closure processing (the focus here is on the processing of attribute values, so there is no)/Xeot; # Example input $ content1 = <eot God of War Ah Republican> eot; $ content2 = <eot God of War Ah Republic "> eot; echo $ pattern. chr (10); preg_match ($ pattern, $ content1, $ matches); print_r ($ matches); preg_match ($ pattern, $ content2, $ matches ); print_r ($ matches );
------ Solution --------------------
No one left you. I will support it.
------ Solution --------------------
Well, the lgg201 is generally dry ....
Wait for the test to be available. do not find a bug ....
------ Solution --------------------
Yeah!
$ Content1 = <eot
Eot;
This is missing
------ Solution --------------------
Warning: preg_match () [function. preg-match]: Unknown modifier 't'in ....
------ Solution --------------------
Building separation line
------ Solution --------------------
Well, this cannot be broken through ....
Frankly speaking, I have not understood this regular expression yet. if you are free, I will study it ~~
------ Solution --------------------
To lgg201.
Can you briefly describe the situation where you need such a match?