Return to Snippet

Revision: 39521
at January 18, 2011 04:13 by kendsnyder


Initial Code
/**
 * Check if haystack string ends with needle string
 * 
 * @param string $haystack
 * @param string $needle
 * @param boolean $caseSensitive (default true)
 * 
 */
function endsWith($haystack, $needle, $caseSensitive = true) {
	if ($caseSensitive) {
		return substr($haystack, -1 * strlen($needle)) == $needle;	
	} else {
		return strtoupper(substr($haystack, -1 * strlen($needle))) == strtoupper($needle);
	}
}

/**
 * Check if haystack string begins with needle string
 * 
 * @param string $haystack
 * @param string $needle
 * @param boolean $caseSensitive (default true)
 * 
 */
function beginsWith($haystack, $needle, $caseSensitive = true) {
	if ($caseSensitive) {
		return substr($haystack, 0, strlen($needle)) == $needle;	
	} else {
		return strtoupper(substr($haystack, 0, strlen($needle))) == strtoupper($needle);
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
String ends with and begins with

Initial Tags

                                

Initial Language
PHP