Skip to content

Commit 2c27245

Browse files
committed
Add Str::containsAny() and containsAll()
1 parent 65b1f14 commit 2c27245

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/common/Str.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ public static function contains(string $string, string $find): bool
9393
return strpos($string, $find) !== false;
9494
}
9595

96+
/**
97+
* @param string[] $find
98+
*/
99+
public static function containsAny(string $string, array $find): bool
100+
{
101+
foreach ($find as $value) {
102+
if (strpos($string, $value) !== false) {
103+
return true;
104+
}
105+
}
106+
107+
return false;
108+
}
109+
110+
/**
111+
* @param string[] $find
112+
*/
113+
public static function containsAll(string $string, array $find): bool
114+
{
115+
foreach ($find as $value) {
116+
if (strpos($string, $value) === false) {
117+
return false;
118+
}
119+
}
120+
121+
return true;
122+
}
123+
96124
public static function substring(string $string, int $start, ?int $length = null): string
97125
{
98126
return Strings::substring($string, $start, $length);

0 commit comments

Comments
 (0)