@@ -16,7 +16,7 @@ function GenerateRandomString(int $length = 16, string $type = 'lower&num'): str
16
16
$ strPol = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ' ;
17
17
}
18
18
$ max = strlen ($ strPol ) - 1 ;
19
- for ($ i = 0 ; $ i < $ length ; $ i ++)
19
+ for ($ i = 0 ; $ i < $ length ; $ i ++)
20
20
$ s .= $ strPol [mt_rand (0 , $ max )];
21
21
return $ s ;
22
22
}
@@ -27,11 +27,11 @@ function strRealLength(string $str): int {
27
27
$ json = json_encode ($ str );
28
28
$ json = substr ($ json , 1 , strlen ($ json ) - 2 );
29
29
$ ret = 0 ;
30
- for ($ i = 0 , $ l = strlen ($ json ); $ i < $ l ; ++ $ i ) {
31
- if ($ json{ $ i } != '\\' )
32
- ++ $ ret ;
33
- else {
34
- if ($ json{ $ i + 1 } == 'u ' && ($ json{ $ i + 2 } == 'd ' || $ json{ $ i + 2 } == 'e ' )) {
30
+ for ($ i = 0 , $ l = strlen ($ json ); $ i < $ l ; ++$ i ) {
31
+ if ($ json[ $ i ] != '\\' ) {
32
+ ++$ ret ;
33
+ } else {
34
+ if ($ json[ $ i + 1 ] == 'u ' && ($ json[ $ i + 2 ] == 'd ' || $ json[ $ i + 2 ] == 'e ' )) {
35
35
$ offset_to_add = 11 ;
36
36
$ ret += 2 ;
37
37
} else {
@@ -43,18 +43,19 @@ function strRealLength(string $str): int {
43
43
}
44
44
return $ ret ;
45
45
}
46
- function strRealSub(string $ str , int $ start , int $ length = NULL , ?callable $ if_sub_call_back = NULL ): string {
46
+ function strRealSub (string $ str , int $ start , int $ length = null , ?callable $ if_sub_call_back = null ): string {
47
47
$ json = json_encode ($ str );
48
48
$ json = substr ($ json , 1 , strlen ($ json ) - 2 );
49
49
$ l = strlen ($ json );
50
- if ($ l == 0 )
50
+ if ($ l == 0 ) {
51
51
return '' ;
52
+ }
52
53
$ ret = [];
53
- for ($ i = 0 ; $ i < $ l ; ++ $ i ) {
54
- if ($ json{ $ i } != '\\' )
55
- $ ret [] = $ json{ $ i } ;
56
- else {
57
- if ($ json{ $ i + 1 } == 'u ' && ($ json{ $ i + 2 } == 'd ' || $ json{ $ i + 2 } == 'e ' )) {
54
+ for ($ i = 0 ; $ i < $ l ; ++$ i ) {
55
+ if ($ json[ $ i ] != '\\' ) {
56
+ $ ret [] = $ json[ $ i ] ;
57
+ } else {
58
+ if ($ json[ $ i + 1 ] == 'u ' && ($ json[ $ i + 2 ] == 'd ' || $ json[ $ i + 2 ] == 'e ' )) {
58
59
$ offset_to_add = 11 ;
59
60
$ s = '" ' . substr ($ json , $ i , 12 ) . '" ' ;
60
61
} else {
@@ -69,22 +70,23 @@ function strRealSub(string $str, int $start, int $length = NULL, ?callable $if_s
69
70
}
70
71
$ retstr = implode ('' , array_slice ($ ret , $ start , $ length ));
71
72
if (isset ($ if_sub_call_back )) {
72
- if ($ start > 0 )
73
- $ if_sub_call_back ($ retstr , FALSE );
74
- elseif ($ start + $ length < count ($ ret ))
75
- $ if_sub_call_back ($ retstr , TRUE );
73
+ if ($ start > 0 ) {
74
+ $ if_sub_call_back ($ retstr , false );
75
+ } elseif ($ start + $ length < count ($ ret )) {
76
+ $ if_sub_call_back ($ retstr , true );
77
+ }
76
78
}
77
79
return $ retstr ;
78
80
}
79
81
function removeEmoji (string $ str ): string {
80
82
$ json = json_encode ($ str );
81
83
$ json = substr ($ json , 1 , strlen ($ json ) - 2 );
82
84
$ newstr = '' ;
83
- for ($ i = 0 , $ l = strlen ($ json ); $ i < $ l ; ++ $ i ) {
84
- if ($ json{ $ i } != '\\' )
85
- $ newstr .= $ json{ $ i } ;
86
- else {
87
- if ($ json{ $ i + 1 } == 'u ' && ($ json{ $ i + 2 } == 'd ' || $ json{ $ i + 2 } == 'e ' )) {
85
+ for ($ i = 0 , $ l = strlen ($ json ); $ i < $ l ; ++$ i ) {
86
+ if ($ json[ $ i ] != '\\' ) {
87
+ $ newstr .= $ json[ $ i ] ;
88
+ } else {
89
+ if ($ json[ $ i + 1 ] == 'u ' && ($ json[ $ i + 2 ] == 'd ' || $ json[ $ i + 2 ] == 'e ' )) {
88
90
$ offset_to_add = 11 ;
89
91
$ newstr .= '? ' ;
90
92
} else {
0 commit comments