strlen( $string ) ) { return false; } $string = substr( $string, 0, $len ); if ( $case_sensitive ) { return strcmp( $string, $starts_with ) === 0; } return strcasecmp( $string, $starts_with ) === 0; } /** * Checks to see whether or not a string ends with another. * * @param string $string The string we want to check. * @param string $ends_with The string we're looking for at the end of $string. * @param bool $case_sensitive Indicates whether the comparison should be case-sensitive. * * @return bool True if the $string ends with $ends_with, false otherwise. */ public static function ends_with( string $string, string $ends_with, bool $case_sensitive = true ): bool { $len = strlen( $ends_with ); if ( $len > strlen( $string ) ) { return false; } $string = substr( $string, -$len ); if ( $case_sensitive ) { return strcmp( $string, $ends_with ) === 0; } return strcasecmp( $string, $ends_with ) === 0; } }