PHP intercepts string and retains full XML tag function code _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.