8May/090
PHP string ends with
There's a hundred ways to do this, but here's the one I came up with. It doesn't use regex's so it should be pretty quick.
function ends_with($str, $suffix) {
return substr($str, -strlen($suffix)) == $suffix;
}
function starts_with($str, $prefix) {
return substr($str, 0, strlen($prefix)) == $prefix;
}
return substr($str, -strlen($suffix)) == $suffix;
}
function starts_with($str, $prefix) {
return substr($str, 0, strlen($prefix)) == $prefix;
}
For completeness, I added the corresponding starts_with function.