Automattic\WooCommerce\Utilities
StringUtil::starts_with()
Checks to see whether or not a string starts with another.
Method of the class: StringUtil{}
No Hooks.
Return
true|false
. True if the $string starts with $starts_with, false otherwise.
Usage
$result = StringUtil::starts_with( $string, $starts_with, $case_sensitive ): bool;
- $string(string) (required)
- The string we want to check.
- $starts_with(string) (required)
- The string we're looking for at the start of $string.
- $case_sensitive(true|false)
- Indicates whether the comparison should be case-sensitive.
Default: true
StringUtil::starts_with() StringUtil::starts with code WC 9.4.2
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; }