首頁 > php教程 > PHP源码 > php文章摘要 [源程序]

php文章摘要 [源程序]

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-08 17:32:51
原創
1046 人瀏覽過
<script>ec(2);</script>

// PHP 4.3 or above needed
define("BRIEF_LENGTH", 800);        //Word amount of the Briefing of an Article
function Generate_Brief($text){
    global $Briefing_Length;
    if(strlen($text)     $Foremost = substr($text, 0, BRIEF_LENGTH);
    $re = "/]*(>?)/i";
    $Single = "/BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT/i";    
    
    $Stack = array(); $posStack = array();
    preg_match_all($re,$Foremost,$matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
    
    /*    [Child-matching Specification]:
        
        $matches[$i][1] : A "/" charactor indicating whether current "<...>" Friction is Closing Part
        $matches[$i][2] : Element Name.
        $matches[$i][3] : Right > of a "<...>" Friction    */
    for($i = 0 ; $i         if($matches[$i][1][0] == ""){
            $Elem = $matches[$i][2][0];
            if(preg_match($Single,$Elem) && $matches[$i][3][0] !=""){
                continue;
            }
            array_push($Stack, strtoupper($matches[$i][2][0]));
            array_push($posStack, $matches[$i][2][1]);            
            if($matches[$i][3][0] =="") break;
        }else{
            $StackTop = $Stack[count($Stack)-1];
            $End = strtoupper($matches[$i][2][0]);
            if(strcasecmp($StackTop,$End)==0){
                array_pop($Stack);
                array_pop($posStack);
                if($matches[$i][3][0] ==""){
                    $Foremost = $Foremost.">";
                }
            }
        }        
    }
    $cutpos = array_shift($posStack) - 1;    
    $Foremost = substr($Foremost,0,$cutpos);
    return $Foremost;
};

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
javascript - js正規符合特定字串
來自於 1970-01-01 08:00:00
0
0
0
為什麼說非物件呼叫成員函數fetch()
來自於 1970-01-01 08:00:00
0
0
0
資料庫設定檔必須要用二維數組
來自於 1970-01-01 08:00:00
0
0
0
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板