Chinese characters intercept in PHP

xiaoxiao2021-03-06  107

It seems that this problem will always ask the functions used in the forum, and they have seen the PHP column of the master. The method is simple.

First we look at the two methods for previous applications

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

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;

}

Let's take a look at the way, simple?

$ LEN = 19;

$ TEXT = "How to display a long headline of the news only to some words in front, replace it later?";

Echo Strlen ($ text) <= $ get $ TEXT: (Substr ($ text, 0, $ len) .chr (0). "...");

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

New Post(0)