Automattic\WooCommerce\Utilities

StringUtil::ends_with()public staticWC 1.0

Checks to see whether or not a string ends with another.

Метод класса: StringUtil{}

Хуков нет.

Возвращает

true|false. True if the $string ends with $ends_with, false otherwise.

Использование

$result = StringUtil::ends_with( $string, $ends_with, $case_sensitive ): bool;
$string(строка) (обязательный)
The string we want to check.
$ends_with(строка) (обязательный)
The string we're looking for at the end of $string.
$case_sensitive(true|false)
Indicates whether the comparison should be case-sensitive.
По умолчанию: true

Код StringUtil::ends_with() WC 8.7.0

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;
}