Home > Backend Development > PHP Tutorial > PHP intercepts the string and retains the complete xml tag function code_PHP tutorial

PHP intercepts the string and retains the complete xml tag function code_PHP tutorial

WBOY
Release: 2016-07-21 15:13:57
Original
1137 people have browsed it

Copy code The code is as follows:

/**
* 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(<<
#该正则表达式解析xml标签, 标签属性内部支持转义符"\", 支持对"\"自身和对应引号的转义
<(\w+) #标签开始
(?: #属性列表
\s+ #前置空格
\w+ #属性名
\s* #属性名后的空白(为了兼容)
= #属性名值之间的等号
\s* #属性值前的空白(为了兼容)
(?: #属性值(引号处理)
" #双引号的情况
(?:
\\\\\\\\ #吃掉连续两个转义符(表示转义符自身)

\\\\" #吃掉转义符接着一个引号(表示转义的引号)

[^"\\\\]* #其他字符
)*
"

' #单引号情况
(?:
\\\\\\\\ #吃掉连续两个转义符(表示转义符自身)

\\\\' #吃掉转义符接着一个引号(表示转义的引号)

[^'\\\\]* #其他字符
)*
'
)
)*

    .*?               #标签内容 
         #结束标签 
    ;x 
    heredoc 
    , $s, $matches, PREG_OFFSET_CAPTURE, $o); 
        if ( $is_match ) { 
            foreach ( $matches[0] as $match ) { 
                $o0 = $match[1]; 
                #标签左边界越过截取目标右边界, 退出 
if ( $o0 >= $o + $l ) break;
                                                                                    $o0 + $l0 < $o + $l ) continue; >                                                                                                                                                                 ) .chr(10);





http://www.bkjia.com/PHPjc/326438.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/326438.html
TechArticle

Copy the code as follows: ?php /*** author: goosman * blog: http://blog.csdn.net/lgg201 * mail: lgg860911@yahoo.com.cn*/ $str = '0123456789a012/a0123456789'; function substr_rem...

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template