Treatment of Chinese characters in PHP, 2 classes that appear in garbled

zhaozj2021-02-16  56

-------------------------------------------------- -------------

Function Msubstr ($ STR, $ START, $ LEN) {

$ Strlen = $ start $ LEN;

For ($ I = 0; $ I <$ Strlen; $ I ) {

IF (Substr ($ Str, $ I, 1)> 0xA0) {

$ Tmpstr. = Substr ($ STR, $ I, 2);

$ i ;

Else

$ Tmpstr. = SUBSTR ($ STR, $ I, 1);

}

Return $ TMPSTR;

}

-------------------------------------

$ Str = "This character is long, ^ _ ^";

$ Short_STR = Showsh ($ STR, 4); // Intercept 4 Chinese characters in front, the result is: this character ...

Echo "$ Short_STR";

Function Csubstr ($ STR, $ START, $ LEN)

{

$ Strlen = Strlen ($ STR);

$ clen = 0;

For ($ I = 0; $ I <$ Strlen; $ i , $ Clen )

{

IF ($ clen> = $ start $ g)

Break;

IF (Substr ($ Str, $ I, 1)> 0xA0)

{

IF ($ clen> = $ s)

$ Tmpstr. = Substr ($ STR, $ I, 2);

$ i ;

}

Else

{

IF ($ clen> = $ s)

$ Tmpstr. = SUBSTR ($ STR, $ I, 1);

}

}

Return $ TMPSTR;

}

Function Showsh ($ STR, $ LEN)

{

$ TEMPSTR = CSUBSTR ($ STR, 0, $ LEN);

IF ($ STR <> $ TEMPSTR)

$ Tempstr. = "..."; // What is the end of the end, modify it here.

Return $ TEMPSTR;

}

转载请注明原文地址:https://www.9cbs.com/read-19189.html

New Post(0)