Php digest generation function (no garbled code ). When using the strip_tags () command, you must add strip_tags () to the function. The following figure shows the strip_tags () content of the Digest to be generated. of course, you can add strip_tags () directly to the function, add it by yourself. The following are functions:
The code is as follows:
Function cutstr ($ string, $ length, $ charset, $ dot) {// character, truncation length, character set, and Terminator
If (strlen ($ string) <= $ length ){
Return $ string;
}
$ Pre = chr (1 );
$ End = chr (1 );
// Protect special strings
$ String = str_replace (array ('&', '"', '<', '>'), array ($ pre. '&'. $ end, $ pre. '"'. $ end, $ pre. '<'. $ end, $ pre. '> '. $ end), $ string );
$ Strcut = '';
If (strtolower ($ charset) = 'utf-8 '){
$ N = $ tn = $ noc = 0;
While ($ n <strlen ($ string )){
$ T = ord ($ string [$ n]);
If ($ t = 9 | $ t = 10 | (32 <= $ t & $ t <= 126 )){
$ Tn = 1; $ n ++; $ noc ++;
} Elseif (194 <=$ t & $ t <= 223 ){
$ Tn = 2; $ n + = 2; $ noc + = 2;
} Elseif (224 <=$ t & $ t <= 239 ){
$ Tn = 3; $ n + = 3; $ noc + = 2;
} Elseif (240 <=$ t & $ t <= 247 ){
$ Tn = 4; $ n + = 4; $ noc + = 2;
} Elseif (248 <=$ t & $ t <= 251 ){
$ Tn = 5; $ n + = 5; $ noc + = 2;
} Elseif ($ t = 252 | $ t = 253 ){
$ Tn = 6; $ n + = 6; $ noc + = 2;
} Else {
$ N ++;
}
If ($ noc >=$ length ){
Break;
}
}
If ($ noc> $ length ){
$ N-= $ tn;
}
$ Strcut = substr ($ string, 0, $ n );
} Else {
For ($ I = 0; $ I <$ length; $ I ++ ){
$ Strcut. = ord ($ string [$ I]) & gt; 127? $ String [$ I]. $ string [++ $ I]: $ string [$ I];
}
}
// Restore a special string
$ Strcut = str_replace (array ($ pre. '&'. $ end, $ pre. '"'. $ end, $ pre. '<'. $ end, $ pre. '> '. $ end), array ('&', '"', '<', '>'), $ strcut );
// Fixed the problem of special string segment truncation.
$ Pos = strrpos ($ s, chr (1 ));
If ($ pos! = False ){
$ Strcut = substr ($ s, 0, $ pos );
}
Return $ strcut. $ dot;
}
Merge (). of course, you can add strip_tags () directly to the function. I didn't do it. add it myself. Below is a letter...