Return to Snippet

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


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

Revision: 12523
at August 8, 2009 11:18 by Vordreller


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

Revision: 12522
at July 23, 2009 16:32 by Vordreller


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

Revision: 12521
at July 23, 2009 16:32 by Vordreller


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

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


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

Revision: 12519
at March 24, 2009 07:41 by Vordreller


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

Revision: 12518
at March 17, 2009 23:07 by Vordreller


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

Initial URL

                                

Initial Description
The counterpart of this snippet: [http://snipplr.com/view/13213/check-if-a-string-ends-with-another-string/][1]

This one checks if a strings begins with another string. Again, third paramter is optional, if you don't set it, the comparison will be case-sensitive.


  [1]: http://snipplr.com/view/13213/check-if-a-string-ends-with-another-string/

Initial Title
Check if a string begins with another string

Initial Tags

                                

Initial Language
PHP