/startswith.php Secret
Created
September 19, 2016 16:44
starts with + ends with functions
This file contains hidden or 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
<?php | |
abstract class Str { | |
public static function StartsWith($haystack, $needle, $case_insensitive=false) { | |
if($case_insensitive) { | |
$haystack = strtolower($haystack); | |
$needle = strtolower($needle); | |
} | |
return substr($haystack, 0, strlen($needle)) === $needle; | |
} | |
public static function EndsWith($haystack, $needle, $case_insensitive=false) { | |
if($case_insensitive) { | |
$haystack = strtolower($haystack); | |
$needle = strtolower($needle); | |
} | |
return substr($haystack, -strlen($needle)) === $needle; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment