Ec (2); PHP4.3oraboveneededdefine (& quot; BRIEF_LENGTH & quot;, 800); & nbsp; & nbsp; WordamountoftheBriefingofanArticlefunctionGenerate_Brief ($ text) {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) <= BRIEF_LENGTH) return $ text;
$ Foremost = substr ($ text, 0, BRIEF_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) [^>] * (> ?) /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 <count ($ matches); $ 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;
};