You can use this in PHP versions less than 8. <?php function str_starts_with ( $haystack, $needle ) { return strpos( $haystack , $needle ) === 0; }