Last active
March 27, 2017 18:34
-
-
Save rodrigoslayertech/2fe79c461a2777483e9677a4e7163013 to your computer and use it in GitHub Desktop.
PHP __String Class
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
final class __String | |
{ | |
public static function search(string $haystack, $needle, int $offset = null){ | |
$needles = (array)$needle; | |
$found = null; | |
foreach($needles as $needle){ | |
$position = strpos($haystack, $needle, $offset); | |
if($position !== false){ | |
$found = $needle; | |
break; | |
} | |
} | |
return new class($position, $found){ | |
public $position; | |
public $found; | |
public function __Construct($position, $found){ | |
$this->position = $position; | |
$this->found = $found; | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment