php截取html字符串及自动补全html标签的方法(2)

function text_zhaiyao($text,$length){ //文章摘要生成函数  $test:内容 $length:摘要长度
    global $Briefing_Length;
    mb_regex_encoding("UTF-8");
    if(mb_strlen($text) <= $length ) return $text;
    $Foremost = mb_substr($text, 0, $length);
    $re = "<(/?)
    (P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|TABLE|TR|TD|TH|INPUT|SELECT|TEXTAREA|OBJECT|A|UL|OL|LI|
    BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT|SPAN)[^>]*(>?)";
    $Single = "/BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT|BR/i";
     
    $Stack = array(); $posStack = array();
     
    mb_ereg_search_init($Foremost, $re, 'i');
     
    while($pos = mb_ereg_search_pos()){
    $match = mb_ereg_search_getregs();
    /* [Child-matching Formulation]:
     
    $matche[1] : A "https://www.jb51.net/" charactor indicating whether current "<...>" Friction is
    Closing Part
    $matche[2] : Element Name.
    $matche[3] : Right > of a "<...>" Friction
    */
    if($match[1]==""){
    $Elem = $match[2];
    if(mb_eregi($Single, $Elem) && $match[3] !=""){
    continue;
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/9531c660e157e096d291b6b64cb7bf9e.html