PHP Function to check if string ends with given substring ends_with()

Here is small php string function to determine that string is end with given substring, characters or symbols.

Source Code:

 * Determine if a given string ends with a given substring.
 * @param  string  $haystack
 * @param  string|array  $needles
 * @return bool

function ends_with($haystack, $needles)
	foreach ((array) $needles as $needle)
		if ((string) $needle === substr($haystack, -strlen($needle))) return true;
return false;

Output / Usage:


$string = "EduZip is also filled with the fully solved previous exam papers";

    echo 'TRUE';
} else {
    echo 'FALSE';

Comments: (Your feedback is valuable to us)

Davinder Singh 3 years ago Reply

thanks for this php string ends with function