File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 22
22
use function base64_encode ;
23
23
use function count ;
24
24
use function crc32 ;
25
+ use function escapeshellarg ;
25
26
use function gethostname ;
26
27
use function hash ;
27
28
use function hex2bin ;
28
29
use function is_int ;
29
30
use function is_string ;
30
31
use function mb_strwidth ;
31
32
use function microtime ;
33
+ use function preg_match ;
32
34
use function preg_split ;
33
35
use function random_bytes ;
34
36
use function random_int ;
38
40
use function str_word_count ;
39
41
use function strlen ;
40
42
use function strpos ;
43
+ use function strtr ;
41
44
use function substr ;
42
45
use function trim ;
43
46
use function uniqid ;
@@ -375,6 +378,17 @@ public static function deleteStripSpace($fileName, $type = 0)
375
378
return preg_replace ($ preg_arr , '' , $ data );
376
379
}
377
380
381
+ /**
382
+ * @param string $template
383
+ * @param array $vars
384
+ *
385
+ * @return string
386
+ */
387
+ public static function replaces (string $ template , array $ vars ): string
388
+ {
389
+ return strtr ($ template , $ vars );
390
+ }
391
+
378
392
////////////////////////////////////////////////////////////
379
393
/// Other
380
394
////////////////////////////////////////////////////////////
@@ -399,6 +413,18 @@ public static function utf8WordCount(string $str): int
399
413
return count (preg_split ('~[^\p{L}\p{N} \']+~u ' , $ str ));
400
414
}
401
415
416
+ /**
417
+ * Escapes a token through escape shell arg if it contains unsafe chars.
418
+ *
419
+ * @param string $token
420
+ *
421
+ * @return string
422
+ */
423
+ public static function escapeToken (string $ token ): string
424
+ {
425
+ return preg_match ('{^[\w-]+$} ' , $ token ) ? $ token : escapeshellarg ($ token );
426
+ }
427
+
402
428
/**
403
429
* @param string $arg
404
430
*
You can’t perform that action at this time.
0 commit comments