Skip to content

Instantly share code, notes, and snippets.

@ReekenX
Created March 19, 2014 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ReekenX/9635641 to your computer and use it in GitHub Desktop.
Save ReekenX/9635641 to your computer and use it in GitHub Desktop.
Functions startsWith() and endsWith() like in Python
<?php
function startsWith($haystack, $needle) {
return !strncmp($haystack, $needle, strlen($needle));
}
function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment