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

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
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}