Update as of 2021, PHP > 8.0
PHP 8.0
has introduced str_starts_with
and str_ends_with
.
str_starts_with( string $haystack , string $needle ) : bool
str_ends_with( string $haystack , string $needle ) : bool
With your example we would have:
$str = '|apples}';echo str_starts_with( $str, '|' ); //... true || 1echo str_ends_with( $str, '}' ); //... true || 1