Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
amirpny authored Oct 2, 2021
1 parent 8df3890 commit fcde333
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
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']));
‌```
19 changes: 19 additions & 0 deletions composer.json
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"
}
}
}
42 changes: 42 additions & 0 deletions src/Str.php
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;
}
}

0 comments on commit fcde333

Please sign in to comment.