30 seconds of PHP

  Back to Home

endsWith

stringbeginner

Checks if a string is ends with a given substring.

Use strrpos() in combination with strlen to find the position of $needle in $haystack.

function endsWith($haystack, $needle)
{
  return strrpos($haystack, $needle) === (strlen($haystack) - strlen($needle));
}