The php code that intercepts the string and retains the complete xml tag. if you need it, refer
The code is as follows:
/**
* Author: goosman
* Blog: http://blog.csdn.net/lgg201
* Mail: lgg860911@yahoo.com.cn
*/
$ Str = '000000 ';
Function substr_remain_tag ($ s, $ o, $ l ){
$ Is_match = preg_match_all (<
# This regular expression parses xml tags. the tag attributes support the escape character "\" and escape the "\" itself and corresponding quotation marks.
<(\ W +) # label start
(? : # Attribute list
\ S + # leading space
\ W + # attribute name
\ S * # blank space after attribute name (for compatibility)
= # Equal sign between attribute name values
\ S * # blank before attribute values (for compatibility)
(? : # Attribute values (quotes)
"# Double quotation marks
(? :
\\\\\\\\# Eat two consecutive escape characters (indicating the escape character itself)
\\\\ "# Eat the escape character followed by a quotation mark (indicating the escape quotation mark)
[^ "\\\\] * # Other characters
)*
"
'# Single quotes
(? :
\\\\\\\\# Eat two consecutive escape characters (indicating the escape character itself)
\\\\' # Eat the escape character followed by a quotation mark (indicating the escape quotation mark)
[^ '\\\\] * # Other characters
)*
'
)
)*
>
.*? # Tag content
# End tag
; X
Heredoc
, $ S, $ matches, PREG_OFFSET_CAPTURE, $ o );
If ($ is_match ){
Foreach ($ matches [0] as $ match ){
$ O0 = $ match [1];
# The left boundary of the tag crosses the right boundary of the capture target and exits.
If ($ o0 >=$ o + $ l) break;
$ L0 = strlen ($ match [0]);
# The right boundary of the tag is within the right boundary of the captured target. continue
If ($ o0 + $ l0 <$ o + $ l) continue;
# Tag cross-border processing
$ L = $ o0 + $ l0-$ o;
Break;
}
}
Return substr ($ s, $ o, $ l );
}
Echo $ str. chr (10 );
Echo substr_remain_tag ($ str, 0, 20). chr (10 );