Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
stringhelper.php
1<?php
9namespace Bitrix\Main\Text;
10
17{
25 public static function strtoupper($str)
26 {
27 static $cache;
28
29 if (empty($cache[$str]))
30 {
31 $cache[$str] = mb_strtoupper($str);
32 }
33
34 return $cache[$str];
35 }
36
44 public static function camel2snake($str)
45 {
46 return mb_strtolower(preg_replace('/(.)([A-Z])/', '$1_$2', $str));
47 }
48
56 public static function snake2camel($str)
57 {
58 $str = str_replace('_', ' ', mb_strtolower($str));
59 return str_replace(' ', '', ucwords($str));
60 }
61
70 public static function str_replace($search, $replace, $str)
71 {
72 if (is_array($str))
73 {
74 foreach ($str as $key => $value)
75 {
76 if (is_scalar($value))
77 {
78 $str[$key] = str_replace($search, $replace, $value);
79 }
80 }
81 }
82 elseif (is_scalar($str))
83 {
84 $str = str_replace($search, $replace, $str);
85 }
86
87 return $str;
88 }
89
96 public static function isStringable($value): bool
97 {
98 return !is_array($value)
99 && (
100 (!is_object($value) && settype($value, 'string') !== false)
101 || (is_object($value) && method_exists($value, '__toString'))
102 );
103 }
104}
static str_replace($search, $replace, $str)