# Determine whether a position is the left or right part of a Chinese character or not a Chinese character
# Return Value-1 left 0 is not a Chinese character 1 right
# Usage
/*
$ A = 'this is Chinese ';
Print is_chinese ($ A, 1); // 0
Print is_chinese ($ A, 8); //-1
Print is_chinese ($ A, 9); // 1
*/
Function is_chinese (& $ STR, $ location ){
$ CH = true;
$ I = $ location;
While (ord ($ STR [$ I])> 0xa0 & $ I> = 0 ){
$ CH =! $ Ch;
$ I --;
}
If ($ I! = $ Location ){
$ F_str = $ ch? 1:-1;
}
Else {
$ F_str = false;
}
Return $ f_str;
}
# Chinese string inversion Function
# If a string with Chinese characters is reversed using strrev, garbled characters are generated.
/*
Print cstrrev ('this is Chinese'); // Si siht in the text
*/
Function cstrrev (& $ Str ){
$ Long = strlen ($ Str );
For ($ f_str = '', $ Chinese = false, $ I = $ long-1; $ I >=0; $ I --){
If (ord ($ STR [$ I])> 0xa0 ){
$ Chinese =! $ Chinese;
If ($ Chinese = false ){
$ F_str. = $ STR [$ I]. $ STR [$ I + 1];
}
}
Else {
$ F_str. = $ STR [$ I];
}
}
Return $ f_str;
}
/* Chinese string truncation Function
Some Chinese string truncation functions often have some problems, suchProgramMedium
$ A = "1 medium 2 ";
After two interceptions,
Csubstr ($ STR, $ A, 0, 2 );
Csubstr ($ STR, $ A, 2, 2)
The loading position may point to the right byte of "medium ".
1, 2
Using this function produces the correct result.
Medium, 2
*/
# Start start position, starting from 0
# Long = 0, the string is retrieved from start until the end of the string.
# When ltor is set to true, the characters are obtained from left to right, and when false, the characters are obtained from right to left.
# $ Cn_len the number of Chinese Characters in bytes or words. If the number of words is counted, a Chinese character is counted as one byte.
Function csubstr (& $ STR, $ start = 0, $ long = 0, $ ltor = true, $ cn_len ){
If ($ long = 0) $ long = strlen ($ Str );
If ($ ltor = false) $ STR = cstrrev ($ Str );
If ($ cn_len = 1 ){
For ($ I = 0, $ FS = 0; $ I <$ start; $ FS ++)
$ I + = (ord ($ STR [$ fs]) <= 0xa0 )? 0.5;
For ($ I = 0, $ Fe = $ FS; $ I <$ long; $ Fe ++)
$ I + = (ord ($ STR [$ Fe]) <= 0xa0 )? 0.5;
$ Long = $ Fe-$ FS;
}
Else {
$ FS = (is_chinese ($ STR, $ start) = 1 )? $ Start-1: $ start;
$ Fe = $ long + $ start-1;
$ End = (is_chinese ($ STR, $ Fe) =-1 )? $ Fe-1: $ Fe;
$ Long = $ end-$ FS + 1;
}
$ F_str = substr ($ STR, $ FS, $ long );
If ($ ltor = false) $ f_str = cstrrev ($ f_str );
Return $ f_str;
}
# Retrieve the left string
# When cn_len = 2, $ long takes the number of words on the left and vice versa.
Function cleft (& $ STR, $ long, $ cn_len = 2 ){
$ F_str = csubstr ($ STR, 0, $ long, true, $ cn_len );
Return $ f_str;
}
# Retrieving the right string
Function cright (& $ STR, $ long, $ cn_len = 2 ){
$ F_str = cstrrev ($ Str );
$ F_str = csubstr ($ f_str, 0, $ long, true, $ cn_len );
$ F_str = cstrrev ($ f_str );
Return $ f_str;
}
#ArticleBranch formatting
# There will no longer be any issues caused by line breaks !!!
# Note: each line of the article must be divided by N (CHR (13 ).
# $ Width: the number of characters in each line
# $ BR specify the characters used in each line as the Terminator.
Function ctext_wrap (& $ text, $ width = 60, $ BR = "<br> "){
$ Lines = explode ("N", $ text );
$ Rows = count ($ lines );
For ($ I = 0; $ I <$ rows; $ I ++ ){
$ Len = strlen ($ lines [$ I]);
For ($ J = 0; $ j <$ Len; $ J + = $ width ){
$ P = $ J + $ width-1;
$ K = 0;
If ($ P <$ Len ){
While (! Is_chinese ($ lines [$ I], $ p) & $ lines [$ I] [$ p]! = ''& $ P> $ J ){
$ K ++;
$ P --;
}
If ($ P = $ J) $ k = 0;
}
$ F_str. = csubstr ($ lines [$ I], $ J, $ width-$ K). $ BR;
$ J-= $ K;
}
}
Return $ f_str;
}