how to check if a string ends with another string in php

Solutions on MaxInterview for how to check if a string ends with another string in php by the best coders in the world

showing results for - "how to check if a string ends with another string in php"
Aymeric
13 Apr 2016
1function endsWith($haystack,$needle,$case=true) {
2    //If its case specific
3    if($case){
4      return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
5    }
6    return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
7}