Skip to content

Instantly share code, notes, and snippets.

@snetty
Created March 1, 2013 12:42
Show Gist options
  • Save snetty/5064384 to your computer and use it in GitHub Desktop.
Save snetty/5064384 to your computer and use it in GitHub Desktop.
easy to remember string search functions
function contains($haystack, $needle){
return strpos($haystack, $needle) !== false;
}
function begins_with($haystack, $needle){
return strpos($haystack, $needle) === 0;
}
function ends_with($haystack, $needle){
return strlen($haystack) - strlen($needle) === strrpos($haystack,$needle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment