-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# String Utils | ||
|
||
--- | ||
|
||
Simple string utils for dealing easier with them | ||
|
||
# Installation | ||
|
||
Install using composer: | ||
|
||
``` | ||
composer require queracollege/string-utils | ||
``` | ||
|
||
# Example | ||
|
||
```php | ||
<?php | ||
require __DIR__.'/vendor/autoload.php'; | ||
use \QueraCollege\StringUtils\Str; | ||
var_dump(Str::contains('abcd', ['ab', 'x'])); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "queracollege/string-utils", | ||
"description": "Simple string utils for dealing easier with them", | ||
"keywords": [ | ||
"string", | ||
"utils" | ||
], | ||
"homepage": "https://github.com/amirpny/string-utils", | ||
"license": "MIT", | ||
"type": "library", | ||
"require": { | ||
"php" : "^7.1.3|^8.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"QueraCollege\\StringUtils\\": "src" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace QueraCollege\StringUtils; | ||
|
||
class Str | ||
{ | ||
/** | ||
* Determine if a given string contains a given substring. | ||
* | ||
* @param string $haystack | ||
* @param string|string[] $needles | ||
* @return bool | ||
*/ | ||
public static function contains($haystack, $needles) | ||
{ | ||
foreach ((array) $needles as $needle) { | ||
if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Determine if a given string contains all array values. | ||
* | ||
* @param string $haystack | ||
* @param string[] $needles | ||
* @return bool | ||
*/ | ||
public static function containsAll($haystack, array $needles) | ||
{ | ||
foreach ($needles as $needle) { | ||
if (!static::contains($haystack, $needle)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |