Copy CodeThe 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标签, the Label property supports escape character "\" internally, and supports escaping the "\" itself and the corresponding quotation marks
< (\w+) #标签开始
(?: #属性列表
\s+ #前置空格
\w+ #属性名
\s* #属性名后的空白 (for compatibility)
= #属性名值之间的等号
\s* #属性值前的空白 (for compatibility)
(?: #属性值 (Quote processing)
"#双引号的情况
(?:
\\\\\\\\ #吃掉连续两个转义符 (indicates the escape character itself)
\\\\ "#吃掉转义符接着一个引号 (indicates escaped quotation marks)
[^ "\\\\]* #其他字符
)*
"
' #单引号情况
(?:
\\\\\\\\ #吃掉连续两个转义符 (indicates the escape character itself)
\\\\ ' #吃掉转义符接着一个引号 (indicates escaped quotes)
[^ ' \\\\]* #其他字符
)*
'
)
)*
>
.*? #标签内容
#结束标签
; x
Heredoc
, $s, $matches, preg_offset_capture, $o);
if ($is _match) {
foreach ($matches [0] as $match) {
$o 0 = $match [1];
#标签左边界越过截取目标右边界, exit
if ($o 0 >= $o + $l) break;
$l 0 = strlen ($match [0]);
#标签右边界在截取目标右边界内, go on.
if ($o 0 + $l 0 < $o + $l) continue;
#以下为标签跨边界处理
$l = $o 0 + $l 0-$o;
Break
}
}
Return substr ($s, $o, $l);
}
Echo $str. Chr (10);
Echo Substr_remain_tag ($str, 0, 20). 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 = ' 01 23456789a012/a0123456789 '; function Substr_rem ...