1919use function str_ends_with ;
2020use function str_starts_with ;
2121use function stripos ;
22+ use function strlen ;
2223use function strpos ;
2324use function strrpos ;
2425use function strtolower ;
@@ -276,7 +277,64 @@ public static function strrpos(string $str, string $find, int $offset = 0, strin
276277 }
277278
278279 /**
279- * Assert is start withs one
280+ * @param string $str
281+ * @param string $needle
282+ *
283+ * @return bool
284+ */
285+ public static function startWith (string $ str , string $ needle ): bool
286+ {
287+ return self ::hasPrefix ($ str , $ needle );
288+ }
289+
290+ /**
291+ * @param string $str
292+ * @param string $needle
293+ *
294+ * @return bool
295+ */
296+ public static function hasPrefix (string $ str , string $ needle ): bool
297+ {
298+ return str_starts_with ($ str , $ needle );
299+ }
300+
301+ /**
302+ * @param string $str
303+ * @param string $needle
304+ *
305+ * @return bool
306+ */
307+ public static function isStartWithIC (string $ str , string $ needle ): bool
308+ {
309+ return self ::hasPrefixIC ($ str , $ needle );
310+ }
311+
312+ /**
313+ * @param string $str
314+ * @param string $needle
315+ *
316+ * @return bool
317+ */
318+ public static function startWithIC (string $ str , string $ needle ): bool
319+ {
320+ return self ::hasPrefixIC ($ str , $ needle );
321+ }
322+
323+ /**
324+ * ignore case, the passed $str ends with the $needle string
325+ *
326+ * @param string $str
327+ * @param string $needle
328+ *
329+ * @return bool
330+ */
331+ public static function hasPrefixIC (string $ str , string $ needle ): bool
332+ {
333+ return stripos ($ str , $ needle ) === 0 ;
334+ }
335+
336+ /**
337+ * check $str is start withs one of $needle
280338 *
281339 * @param string $str
282340 * @param string|array $needle
@@ -299,13 +357,13 @@ public static function isStartWiths(string $str, $needle): bool
299357
300358 /**
301359 * @param string $str
302- * @param string $needle
360+ * @param string|array $needle
303361 *
304362 * @return bool
305363 */
306- public static function hasPrefix (string $ str , string $ needle ): bool
364+ public static function startWiths (string $ str , $ needle ): bool
307365 {
308- return str_starts_with ($ str , $ needle );
366+ return self :: isStartWiths ($ str , $ needle );
309367 }
310368
311369 /**
@@ -320,14 +378,16 @@ public static function hasPrefixes(string $str, array $needles): bool
320378 }
321379
322380 /**
381+ * the passed $str ends with the $needle string
382+ *
323383 * @param string $str
324384 * @param string $needle
325385 *
326386 * @return bool
327387 */
328- public static function isEndWiths (string $ str , string $ needle ): bool
388+ public static function hasSuffix (string $ str , string $ needle ): bool
329389 {
330- return self :: hasSuffix ($ str , $ needle );
390+ return str_ends_with ($ str , $ needle );
331391 }
332392
333393 /**
@@ -336,9 +396,68 @@ public static function isEndWiths(string $str, string $needle): bool
336396 *
337397 * @return bool
338398 */
339- public static function hasSuffix (string $ str , string $ needle ): bool
399+ public static function endWithIC (string $ str , string $ needle ): bool
340400 {
341- return str_ends_with ($ str , $ needle );
401+ return self ::hasSuffixIC ($ str , $ needle );
402+ }
403+
404+ /**
405+ * ignore case, check $str is ends with the $needle string
406+ *
407+ * @param string $str
408+ * @param string $needle
409+ *
410+ * @return bool
411+ */
412+ public static function hasSuffixIC (string $ str , string $ needle ): bool
413+ {
414+ $ pos = stripos ($ str , $ needle );
415+
416+ return $ pos !== false && $ pos + strlen ($ needle ) === strlen ($ str );
417+ }
418+
419+ /**
420+ * @param string $str
421+ * @param string|array $needle
422+ *
423+ * @return bool
424+ */
425+ public static function endWiths (string $ str , $ needle ): bool
426+ {
427+ return self ::hasSuffixes ($ str , $ needle );
428+ }
429+
430+ /**
431+ * @param string $str
432+ * @param string|array $needle
433+ *
434+ * @return bool
435+ */
436+ public static function isEndWiths (string $ str , $ needle ): bool
437+ {
438+ return self ::hasSuffixes ($ str , $ needle );
439+ }
440+
441+ /**
442+ * Assert is start withs one
443+ *
444+ * @param string $str
445+ * @param string|array $needles
446+ *
447+ * @return bool
448+ */
449+ public static function hasSuffixes (string $ str , $ needles ): bool
450+ {
451+ if (is_array ($ needles )) {
452+ foreach ($ needles as $ needle ) {
453+ if (str_ends_with ($ str , $ needle )) {
454+ return true ;
455+ }
456+ }
457+ return false ;
458+ }
459+
460+ return str_ends_with ($ str , $ needles );
342461 }
343462
344463 /**
0 commit comments