PHPsubistr truncated string without code
Time UPDATED: 20120102
-
- /**
- * [WebodMin] (C) 2010-2099 Blank Inc.
- * This is NOT a freeware, use is subject to license terms
- *
- **/
- Function subistr ($ string, $ length, $ dot = '...'){
- Global $ charset;
- If (strlen ($ string) <= $ length ){
- Return $ string;
- }
- $ S = '';
- 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;
- }
- $ S = substr ($ string, 0, $ n );
- } Else {
- For ($ I = 0; $ I <$ length; $ I ++ ){
- $ S. = ord ($ string [$ I])> = 127? $ String [$ I]. $ string [++ $ I]: $ string [$ I];
- }
- }
- Return $ s. $ dot;
- }
|