str_ends_with()WC 1.0

Checks if the string ends with the specified substring. Case sensitive.

This is a polyfill for the new PHP function str_ends_with() introduced in PHP version 8.0.

See also similar functions:

1 time — 0.000001 sec (speed of light) | 50000 times — 0.01 sec (speed of light)

No Hooks.

Returns

null. True if the string ($haystack) ends with the substring ($needle), false otherwise.

Usage

str_ends_with( $haystack, $needle );
$haystack(string) (required)
Hay - the string we are checking.
$needle(string) (required)
Needle - the substring that should be at the end of $haystack.

Examples

0

#1 Demo

str_ends_with( 'ABC', 'C' ); // true

str_ends_with( 'ABC', 'A' ); // false

// case sensitive
str_ends_with( 'ABC', 'c' ); // false

// all lines end with an empty string
str_ends_with( 'abc', '' ); // true

str_ends_with() code WC 10.9.4

function str_ends_with(?string $haystack, ?string $needle): bool { return p\Php80::str_ends_with($haystack ?? '', $needle ?? ''); }