Introduction to the PHP Function Str_Starts_With
This article will introduce php function str_starts_with, which performs case-sensitive search for the substring and checks if the string starts with it. It accepts two parameters, the first one being the string to check and the second one is the substring to search for. If the string starts with the specified substring, the function returns true, else it will return false.
In the past, when we had to check if a string starts with a specific substring, we were using functions like strpos or ststr. With the release of php 8.0, we now have two new functions that make the task much easier: str_starts_with() and str_ends_with().
The difference between these two functions is that str_starts_with() performs a case-sensitive search while str_ends_with() doesn’t. The latter function is also a little bit faster than the former (benchmark script).
This feature was included in PHP 8.0 and was well-received, particularly due to the fact that it makes the job much simpler and cleaner. It also works nicely with other string-related functions in PHP, such as str_contains().
With the recent commit [55959] by @oandregal, we will replace all the 0 === strpos(... ) in WP_Theme_JSON class methods with str_starts_with() on PHP