Automattic\WooCommerce\Utilities

StringUtil::starts_with()public staticWC 1.0

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

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

Хуков нет.

Возвращает

true|false. True if the $string starts with $starts_with, false otherwise.

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

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

Код StringUtil::starts_with() WC 8.7.0

public static function starts_with( string $string, string $starts_with, bool $case_sensitive = true ): bool {
	$len = strlen( $starts_with );
	if ( $len > strlen( $string ) ) {
		return false;
	}

	$string = substr( $string, 0, $len );

	if ( $case_sensitive ) {
		return strcmp( $string, $starts_with ) === 0;
	}

	return strcasecmp( $string, $starts_with ) === 0;
}