CKTIS / PHP
str_starts_with()
Check for an exact case-sensitive byte prefix at the first position.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
str_starts_with(string $haystack, string $needle): boolCheck for an exact case-sensitive byte prefix at the first position. An empty needle is a prefix of every string, but a nonempty needle cannot match empty input. Whitespace at the beginning is significant and is not trimmed automatically.
Signature
str_starts_with(string $haystack, string $needle): bool
Example output
[true,false,false,true]
Examples
<?php
echo json_encode([str_starts_with("ID-2","ID-"),str_starts_with(" ID-2","ID-"),str_starts_with("","ID"),str_starts_with("","")]);
Result
[true,false,false,true]