-
- /**
- * author: goosman
- * blog: http://blog.csdn.net/lgg201
- * mail: lgg860911@yahoo.com.cn
- */
-
- $str = '01234567890120123456789';
- function substr_remain_tag($s, $o, $l) {
- $is_match = preg_match_all(<< ;
- #This regular expression parses xml tags. The tag attribute internally supports the escape character "", and supports the escaping of "" itself and the corresponding quotation marks
- <( w+) #Start of tag
- (?: #Attribute list
- s+ #Preceding space
- w+ #Attribute name
- s* #Blank after attribute name (for compatibility)
- = #Equal sign between attribute name values
- s* #Blank before attribute value (for compatibility)
- (?: #Attribute value (quote processing)
- " #Double quote situation
- (?:
- \\\\ #Eat two consecutive escape characters (indicates escape symbol itself)
- |
- \\" #Eat the escape character followed by a quote (representing an escaped quote)
- |
- [^"\\]* #Other characters
- )*
- "
- |
- ' #Single quote Case
- (?:
- \\\\ #Eat two consecutive escape characters (representing the escape character itself)
- |
- \\' #Eat the escape character followed by a quote (representing the escaped quote)
- |
- [^'\\]* #Other characters
- )*
- '
- )
- )*
- >
- .*? #Tag content
- (?1)> #End tag
- ;x
- heredoc
- , $s, $matches, PREG_OFFSET_CAPTURE, $o);
- if ( $is_match ) {
- foreach ( $matches[0] as $match ) {
- $o0 = $match[1];
- #The label left boundary is intercepted when it crosses Right boundary of the target, exit
- if ( $o0 >= $o + $l ) break;
- $l0 = strlen($match[0]);
- #The right boundary of the label is within the right boundary of the intercepted target, continue
- if ( $o0 + $l0 < $o + $l ) continue;
-
- #The following is label 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);
Copy code
|