@@ -111,7 +111,7 @@ public static function regexMatch(string $value, string $rule): bool
111
111
];
112
112
113
113
$ value = \trim ($ value );
114
- $ name = \strtolower ($ rule );
114
+ $ name = \strtolower ($ rule );
115
115
116
116
// 检查是否有内置的正则表达式
117
117
if (isset ($ validate [$ name ])) {
@@ -225,8 +225,8 @@ public static function random($length, array $param = []): string
225
225
], $ param );
226
226
227
227
$ chars = $ param ['chars ' ];
228
- $ max = \strlen ($ chars ) - 1 ; //strlen($chars) 计算字符串的长度
229
- $ str = '' ;
228
+ $ max = \strlen ($ chars ) - 1 ; //strlen($chars) 计算字符串的长度
229
+ $ str = '' ;
230
230
231
231
for ($ i = 0 ; $ i < $ length ; $ i ++) {
232
232
$ str .= $ chars [random_int (0 , $ max )];
@@ -261,6 +261,17 @@ public static function genUid(int $length = 7): string
261
261
return \substr (\hash ('md5 ' , \uniqid ('' , true )), 0 , $ length );
262
262
}
263
263
264
+ /**
265
+ * @param string $string
266
+ * @param int $indent
267
+ * @param string $padStr
268
+ * @return string
269
+ */
270
+ public static function pad (string $ string , $ indent , $ padStr ): string
271
+ {
272
+ return $ indent > 0 ? \str_pad ($ string , $ indent , $ padStr ) : $ string ;
273
+ }
274
+
264
275
/**
265
276
* gen UUID
266
277
* @param int $version
@@ -395,7 +406,7 @@ public static function split2Array(string $path, string $separator = '.'): array
395
406
396
407
/**
397
408
* @param string $string
398
- * @param int $width
409
+ * @param int $width
399
410
* @return array
400
411
*/
401
412
public static function splitByWidth (string $ string , int $ width ): array
@@ -510,10 +521,10 @@ public static function zhSubStr($str, $start = 0, $length = 0, $charset = 'utf-8
510
521
511
522
$ slice = \mb_substr ($ str , $ start , $ length , $ charset );
512
523
} else {
513
- $ re ['utf-8 ' ] = "/[ \x01- \x7f]|[ \xc2- \xdf][ \x80- \xbf]|[ \xe0- \xef][ \x80- \xbf]{2}|[ \xf0- \xff][ \x80- \xbf]{3}/ " ;
524
+ $ re ['utf-8 ' ] = "/[ \x01- \x7f]|[ \xc2- \xdf][ \x80- \xbf]|[ \xe0- \xef][ \x80- \xbf]{2}|[ \xf0- \xff][ \x80- \xbf]{3}/ " ;
514
525
$ re ['gb2312 ' ] = "/[ \x01- \x7f]|[ \xb0- \xf7][ \xa0- \xfe]/ " ;
515
- $ re ['gbk ' ] = "/[ \x01- \x7f]|[ \x81- \xfe][ \x40- \xfe]/ " ;
516
- $ re ['big5 ' ] = "/[ \x01- \x7f]|[ \x81- \xfe]([ \x40- \x7e]| \xa1- \xfe])/ " ;
526
+ $ re ['gbk ' ] = "/[ \x01- \x7f]|[ \x81- \xfe][ \x40- \xfe]/ " ;
527
+ $ re ['big5 ' ] = "/[ \x01- \x7f]|[ \x81- \xfe]([ \x40- \x7e]| \xa1- \xfe])/ " ;
517
528
518
529
\preg_match_all ($ re [$ charset ], $ str , $ match );
519
530
if (\count ($ match [0 ]) <= $ length ) {
@@ -557,7 +568,7 @@ public static function truncate2(string $str, int $start, int $length = null): s
557
568
{
558
569
if (!$ length ) {
559
570
$ length = $ start ;
560
- $ start = 0 ;
571
+ $ start = 0 ;
561
572
}
562
573
563
574
if (\strlen ($ str ) <= $ length ) {
@@ -588,10 +599,10 @@ public static function truncate3(string $text, int $length = 120, array $options
588
599
'html ' => true
589
600
];
590
601
591
- $ options = array_merge ($ default , $ options );
602
+ $ options = array_merge ($ default , $ options );
592
603
$ ellipsis = $ options ['ellipsis ' ];
593
- $ exact = $ options ['exact ' ];
594
- $ html = $ options ['html ' ];
604
+ $ exact = $ options ['exact ' ];
605
+ $ html = $ options ['html ' ];
595
606
596
607
/**
597
608
* @var string $ellipsis
@@ -604,8 +615,8 @@ public static function truncate3(string $text, int $length = 120, array $options
604
615
}
605
616
606
617
$ total_length = self ::strlen (strip_tags ($ ellipsis ));
607
- $ open_tags = $ tags = [];
608
- $ truncate = '' ;
618
+ $ open_tags = $ tags = [];
619
+ $ truncate = '' ;
609
620
preg_match_all ('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/ ' , $ text , $ tags , PREG_SET_ORDER );
610
621
611
622
foreach ($ tags as $ tag ) {
@@ -619,12 +630,12 @@ public static function truncate3(string $text, int $length = 120, array $options
619
630
}
620
631
}
621
632
}
622
- $ truncate .= $ tag [1 ];
633
+ $ truncate .= $ tag [1 ];
623
634
$ content_length = self ::strlen (preg_replace ('/&[0-9a-z]{2,8};|&#[\d]{1,7};|&#x[0-9a-f]{1,6};/i ' , ' ' ,
624
635
$ tag [3 ]));
625
636
626
637
if ($ content_length + $ total_length > $ length ) {
627
- $ left = $ length - $ total_length ;
638
+ $ left = $ length - $ total_length ;
628
639
$ entities_length = 0 ;
629
640
630
641
if (preg_match_all ('/&[0-9a-z]{2,8};|&#[\d]{1,7};|&#x[0-9a-f]{1,6};/i ' , $ tag [3 ], $ entities ,
@@ -643,7 +654,7 @@ public static function truncate3(string $text, int $length = 120, array $options
643
654
break ;
644
655
}
645
656
646
- $ truncate .= $ tag [3 ];
657
+ $ truncate .= $ tag [3 ];
647
658
$ total_length += $ content_length ;
648
659
649
660
if ($ total_length >= $ length ) {
@@ -664,7 +675,7 @@ public static function truncate3(string $text, int $length = 120, array $options
664
675
$ spacepos = self ::strrpos ($ truncate , ' ' );
665
676
if ($ html ) {
666
677
$ truncate_check = self ::substr ($ truncate , 0 , $ spacepos );
667
- $ last_open_tag = self ::strrpos ($ truncate_check , '< ' );
678
+ $ last_open_tag = self ::strrpos ($ truncate_check , '< ' );
668
679
$ last_close_tag = self ::strrpos ($ truncate_check , '> ' );
669
680
670
681
if ($ last_open_tag > $ last_close_tag ) {
@@ -801,7 +812,7 @@ public static function nameChange(string $str, bool $toCamelCase = true): string
801
812
return $ str ;
802
813
}
803
814
804
- $ arr_char = explode ('_ ' , strtolower ($ str ));
815
+ $ arr_char = explode ('_ ' , strtolower ($ str ));
805
816
$ newString = array_shift ($ arr_char );
806
817
807
818
foreach ($ arr_char as $ val ) {
0 commit comments