|
php版本地址
核心部分如下:
復制代碼 代碼如下:
function Generate_Brief(text,length){
if(text.length < length) return text;
var Foremost = text.substr(0,length);
var re = /<(//?)
(BODY|SCRIPT|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)[^>]*(>?)/ig;
var Singlable = /BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT/i
var Stack = new Array(), posStack = new Array();
while(true){
var newone = re.exec(Foremost);
if(newone == null) break;
if(newone[1] == ""){
var Elem = newone[2];
if(Elem.match(Singlable) && newone[3]!= ""){
continue;
}
Stack.push(newone[2].toUpperCase());
posStack.push(newone.index);
if(newone[3] == "") break;
}else{
var StackTop = Stack[Stack.length-1];
var End = newone[2].toUpperCase();
if(StackTop == End){
Stack.pop();
posStack.pop();
if(newone[3] == ""){
Foremost = Foremost+">";
}
}
};
}
var cutpos = posStack.shift();
Foremost = Foremost.substring(0,cutpos);
return Foremost;
}
JavaScript技術(shù):JavaScript 版本自動生成文章摘要,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。