|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Larapulse\Support\Handlers\Str; |
|
4
|
|
|
use Larapulse\Support\Handlers\RegEx; |
|
5
|
|
|
use Illuminate\Support\Str as IlluminateStr; |
|
6
|
|
|
|
|
7
|
|
|
if (!function_exists('str_pop')) { |
|
8
|
|
|
/** |
|
9
|
|
|
* Pop the character off the end of string |
|
10
|
|
|
* |
|
11
|
|
|
* @param string $str |
|
12
|
|
|
* @param string $encoding |
|
13
|
|
|
* |
|
14
|
|
|
* @return bool|string |
|
15
|
|
|
*/ |
|
16
|
|
|
function str_pop(string &$str, string $encoding = null) |
|
17
|
|
|
{ |
|
18
|
|
|
return Str::pop($str, $encoding); |
|
19
|
|
|
} |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
if (!function_exists('str_shift')) { |
|
23
|
|
|
/** |
|
24
|
|
|
* Shift a character off the beginning of string |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $str |
|
27
|
|
|
* @param string $encoding |
|
28
|
|
|
* |
|
29
|
|
|
* @return bool|string |
|
30
|
|
|
*/ |
|
31
|
|
|
function str_shift(string &$str, string $encoding = null) |
|
32
|
|
|
{ |
|
33
|
|
|
return Str::shift($str, $encoding); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (!function_exists('is_regex')) { |
|
38
|
|
|
/** |
|
39
|
|
|
* Validate if RegEx statement is valid |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $regexStatement |
|
42
|
|
|
* |
|
43
|
|
|
* @return bool |
|
44
|
|
|
*/ |
|
45
|
|
|
function is_regex(string $regexStatement) : bool |
|
46
|
|
|
{ |
|
47
|
|
|
return RegEx::isValid($regexStatement); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (!function_exists('str_prepare_regex')) { |
|
52
|
|
|
/** |
|
53
|
|
|
* Prepare string to be safety used in regex |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $string |
|
56
|
|
|
* @param string $quotes |
|
57
|
|
|
* |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
function str_prepare_regex(string $string, $quotes = '/') : string |
|
61
|
|
|
{ |
|
62
|
|
|
return RegEx::prepare($string, $quotes); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if (!function_exists('str_cut_start')) { |
|
67
|
|
|
/** |
|
68
|
|
|
* Cut substring from the beginning of string |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $str |
|
71
|
|
|
* @param string $subString |
|
72
|
|
|
* @param bool $repeat |
|
73
|
|
|
* @param bool $caseSensitive |
|
74
|
|
|
* |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
function str_cut_start( |
|
78
|
|
|
string $str, |
|
79
|
|
|
string $subString = ' ', |
|
80
|
|
|
bool $repeat = false, |
|
81
|
|
|
bool $caseSensitive = false |
|
82
|
|
|
) : string { |
|
83
|
|
|
return Str::cutStart($str, $subString, $repeat, $caseSensitive); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if (!function_exists('str_cut_end')) { |
|
88
|
|
|
/** |
|
89
|
|
|
* Cut substring from the end of string |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $str |
|
92
|
|
|
* @param string $subString |
|
93
|
|
|
* @param bool $repeat |
|
94
|
|
|
* @param bool $caseSensitive |
|
95
|
|
|
* |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
function str_cut_end( |
|
99
|
|
|
string $str, |
|
100
|
|
|
string $subString = ' ', |
|
101
|
|
|
bool $repeat = false, |
|
102
|
|
|
bool $caseSensitive = false |
|
103
|
|
|
) : string { |
|
104
|
|
|
return Str::cutEnd($str, $subString, $repeat, $caseSensitive); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if (!function_exists('str_lower')) { |
|
109
|
|
|
/** |
|
110
|
|
|
* Convert the given string to lower-case |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $value |
|
113
|
|
|
* |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
function str_lower($value) |
|
117
|
|
|
{ |
|
118
|
|
|
return IlluminateStr::lower($value); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
if (!function_exists('str_upper')) { |
|
123
|
|
|
/** |
|
124
|
|
|
* Convert the given string to upper-case |
|
125
|
|
|
* |
|
126
|
|
|
* @param string $value |
|
127
|
|
|
* |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
|
|
function str_upper($value) |
|
131
|
|
|
{ |
|
132
|
|
|
return IlluminateStr::upper($value); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
if (!function_exists('str_title')) { |
|
137
|
|
|
/** |
|
138
|
|
|
* Convert the given string to title case. |
|
139
|
|
|
* |
|
140
|
|
|
* @param string $value |
|
141
|
|
|
* |
|
142
|
|
|
* @return string |
|
143
|
|
|
*/ |
|
144
|
|
|
function str_title($value) |
|
145
|
|
|
{ |
|
146
|
|
|
return IlluminateStr::title($value); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
if (!function_exists('str_length')) { |
|
151
|
|
|
/** |
|
152
|
|
|
* Return the length of the given string. |
|
153
|
|
|
* |
|
154
|
|
|
* @param string $value |
|
155
|
|
|
* @param string $encoding |
|
156
|
|
|
* |
|
157
|
|
|
* @return int |
|
158
|
|
|
*/ |
|
159
|
|
|
function str_length($value, $encoding = null) |
|
160
|
|
|
{ |
|
161
|
|
|
return IlluminateStr::length($value, $encoding); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
if (!function_exists('str_words')) { |
|
166
|
|
|
/** |
|
167
|
|
|
* Limit the number of words in a string. |
|
168
|
|
|
* |
|
169
|
|
|
* @param string $value |
|
170
|
|
|
* @param int $words |
|
171
|
|
|
* @param string $end |
|
172
|
|
|
* |
|
173
|
|
|
* @return string |
|
174
|
|
|
*/ |
|
175
|
|
|
function str_words($value, $words = 100, $end = '...') |
|
176
|
|
|
{ |
|
177
|
|
|
return IlluminateStr::words($value, $words, $end); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
if (!function_exists('str_substr')) { |
|
182
|
|
|
/** |
|
183
|
|
|
* Returns the portion of string specified by the start and length parameters. |
|
184
|
|
|
* |
|
185
|
|
|
* @param string $string |
|
186
|
|
|
* @param int $start |
|
187
|
|
|
* @param int|null $length |
|
188
|
|
|
* |
|
189
|
|
|
* @return string |
|
190
|
|
|
*/ |
|
191
|
|
|
function str_substr($string, $start, $length = null) |
|
192
|
|
|
{ |
|
193
|
|
|
return IlluminateStr::substr($string, $start, $length); |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
if (!function_exists('str_ucfirst')) { |
|
198
|
|
|
/** |
|
199
|
|
|
* Make a string's first character uppercase. |
|
200
|
|
|
* |
|
201
|
|
|
* @param string $string |
|
202
|
|
|
* @return string |
|
203
|
|
|
*/ |
|
204
|
|
|
function str_ucfirst($string) |
|
205
|
|
|
{ |
|
206
|
|
|
return IlluminateStr::ucfirst($string); |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
if (!function_exists('str_starts_with')) { |
|
211
|
|
|
/** |
|
212
|
|
|
* Determine if a given string starts with a given substring. |
|
213
|
|
|
* |
|
214
|
|
|
* @param string $haystack |
|
215
|
|
|
* @param string|array $needles |
|
216
|
|
|
* |
|
217
|
|
|
* @return bool |
|
218
|
|
|
*/ |
|
219
|
|
|
function str_starts_with($haystack, $needles) |
|
220
|
|
|
{ |
|
221
|
|
|
return IlluminateStr::startsWith($haystack, $needles); |
|
222
|
|
|
} |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
if (!function_exists('str_ends_with')) { |
|
226
|
|
|
/** |
|
227
|
|
|
* Determine if a given string ends with a given substring. |
|
228
|
|
|
* |
|
229
|
|
|
* @param string $haystack |
|
230
|
|
|
* @param string|array $needles |
|
231
|
|
|
* |
|
232
|
|
|
* @return bool |
|
233
|
|
|
*/ |
|
234
|
|
|
function str_ends_with($haystack, $needles) |
|
235
|
|
|
{ |
|
236
|
|
|
return IlluminateStr::endsWith($haystack, $needles); |
|
237
|
|
|
} |
|
238
|
|
|
} |
|
239
|
|
|
|