Skip to content

Instantly share code, notes, and snippets.

@mnpenner
Created Sep 19, 2016
Embed
What would you like to do?
starts with + ends with functions
<?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