Skip to content

Instantly share code, notes, and snippets.

@rodrigoslayertech
Last active March 27, 2017 18:34
Show Gist options
  • Save rodrigoslayertech/2fe79c461a2777483e9677a4e7163013 to your computer and use it in GitHub Desktop.
Save rodrigoslayertech/2fe79c461a2777483e9677a4e7163013 to your computer and use it in GitHub Desktop.
PHP __String Class
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