Html string cutting by php, automatically adding unfinished html tags
/* Intercept the html string * @ param $ s string * @ param $ zi length * @ param $ ne: html tag with no Terminator */function G_htmlcut ($ s, $ zi, $ ne = ', br, hr, input, img,') {$ s = preg_replace ('/\ s {2,}/', ', $ s ); $ OS = preg_split ('//', $ s); preg_match_all ('//', $ s, $ or); $ s = ''; $ tag = array (); foreach ($ OS as $ k => $ v) {if ($ v! = ''& $ V! = '') {$ L = strlen ($ v); for ($ I = 0; $ I 127) {$ s. = $ v [$ I]. $ v [++ $ I]. $ v [++ $ I];} else {$ s. = $ v [$ I] ;}$ zi --; if ($ zi <1) {break 2 ;}} preg_match ('/] +) [\ s>] {1}/', $ or [0] [$ k], $ t); $ s. = $ or [0] [$ k]; if (strpos ($ ne ,','. strtolower ($ t [1]). ',') ===false & $ t [1]! = ''& $ T [1]! = '') {$ K = array_search ('', $ tag); if ($ k! = False) {unset ($ tag [$ k]);} else {array_unshift ($ tag, '') ;}} return $ s. implode ('', $ tag );}