Return to Snippet

Revision: 12517
at August 8, 2009 11:20 by Vordreller


Updated Code
function endsWith($haystack,$needle,$case=true) {
    if($case){return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);}
    return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
}

Revision: 12516
at August 8, 2009 11:17 by Vordreller


Updated Code
function endsWith($haystack,$needle,$case=true) {
    if($case){return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);}
    return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),strtolower($needle))===0);
}

Revision: 12515
at July 23, 2009 16:33 by Vordreller


Updated Code
function endsWith($haystack,$needle,$case=true) {
    if($case){return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);}
    return (strcmp(strtolower(substr($haystack, strlen($haystack) - strlen($needle))),strtolower($needle))===0);
}

Revision: 12514
at May 7, 2009 10:33 by Vordreller


Updated Code
function endsWith($haystack,$needle,$case=true) {
 if($case){return (substr($haystack, strlen($haystack) - strlen($needle)) === $needle);}
 return (strtolower(substr($haystack, strlen($haystack) - strlen($needle))) === strtolower($needle));
}

Revision: 12513
at March 24, 2009 07:42 by Vordreller


Updated Code
function endsWith($haystack,$needle,$case=true) {
 if($case){return (substr($haystack, strlen($haystack) - strlen($needle)) === $needle);}
 if(!$case){return (strtolower(substr($haystack, strlen($haystack) - strlen($needle))) === strtolower($needle));}
}

Revision: 12512
at March 17, 2009 23:02 by Vordreller


Initial Code
function endsWith($haystack,$needle,$case=true) {
    if($case){return (substr($haystack, strlen($haystack) - strlen($needle)) === $needle);}
    if(!$case){return (strtolower(substr($haystack, strlen($haystack) - strlen($needle))) === strtolower($needle));}
  }

Initial URL

                                

Initial Description
This piece of code will enable you to check if a string ends with a certain string. Particularly handy when checking filetypes, like is something a jpg or not.
The third parameter is optional, if set to true, than the comparison will be case specific.

Initial Title
Check if a string ends with another string

Initial Tags

                                

Initial Language
PHP