public static function endsWith($haystack, $needle, $case = true) { if ($case) { return strcmp(Unicode::substr($haystack, Unicode::strlen($haystack) - Unicode::strlen($needle)), $needle) === 0; } return strcasecmp(Unicode::substr($haystack, Unicode::strlen($haystack) - Unicode::strlen($needle)), $needle) === 0; }
/** * Validates whether a hexadecimal color value is syntactically correct. * * @param $hex * The hexadecimal string to validate. May contain a leading '#'. May use * the shorthand notation (e.g., '123' for '112233'). * * @return bool * TRUE if $hex is valid or FALSE if it is not. */ public static function validateHex($hex) { // Must be a string. $valid = is_string($hex); // Hash prefix is optional. $hex = ltrim($hex, '#'); // Must be either RGB or RRGGBB. $length = Unicode::strlen($hex); $valid = $valid && ($length === 3 || $length === 6); // Must be a valid hex value. $valid = $valid && ctype_xdigit($hex); return $valid; }
/** * Returns the string length. * * @return int * The length of the string. */ public function count() { return Unicode::strlen($this->string); }