str_starts_with

The timeline below displays how wordpress function str_starts_with has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: .28

/**
 * Polyfill for `str_starts_with()` function added in PHP 8.0.
 *
 * Performs a case-sensitive check indicating if
 * the haystack begins with needle.
 *
 * @since 5.9.0
 *
 * @param string $haystack The string to search in.
 * @param string $needle   The substring to search for in the `$haystack`.
 * @return bool True if `$haystack` starts with `$needle`, otherwise false.
 */
function str_starts_with($haystack, $needle)
{
    if ('' === $needle) {
        return true;
    }
    return 0 === strpos($haystack, $needle);
}