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 2222use function base64_encode ;
2323use function count ;
2424use function crc32 ;
25+ use function escapeshellarg ;
2526use function gethostname ;
2627use function hash ;
2728use function hex2bin ;
2829use function is_int ;
2930use function is_string ;
3031use function mb_strwidth ;
3132use function microtime ;
33+ use function preg_match ;
3234use function preg_split ;
3335use function random_bytes ;
3436use function random_int ;
3840use function str_word_count ;
3941use function strlen ;
4042use function strpos ;
43+ use function strtr ;
4144use function substr ;
4245use function trim ;
4346use function uniqid ;
@@ -375,6 +378,17 @@ public static function deleteStripSpace($fileName, $type = 0)
375378 return preg_replace ($ preg_arr , '' , $ data );
376379 }
377380
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+
378392 ////////////////////////////////////////////////////////////
379393 /// Other
380394 ////////////////////////////////////////////////////////////
@@ -399,6 +413,18 @@ public static function utf8WordCount(string $str): int
399413 return count (preg_split ('~[^\p{L}\p{N} \']+~u ' , $ str ));
400414 }
401415
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+
402428 /**
403429 * @param string $arg
404430 *
You can’t perform that action at this time.
0 commit comments