CKTIS / PHP
str_starts_with()
Comprueba un prefijo de bytes exacto al inicio distinguiendo mayúsculas.
Versión: PHP 8.4; repository runtime, production runtime not attested
Sintaxis
str_starts_with(string $haystack, string $needle): boolComprueba un prefijo de bytes exacto al inicio distinguiendo mayúsculas. Un patrón vacío es prefijo de toda cadena y uno no vacío no cabe en una entrada vacía. El espacio inicial cuenta y no se elimina.
Firma
str_starts_with(string $haystack, string $needle): bool
Salida del ejemplo
[true,false,false,true]
Ejemplos
<?php
echo json_encode([str_starts_with("ID-2","ID-"),str_starts_with(" ID-2","ID-"),str_starts_with("","ID"),str_starts_with("","")]);
Resultado
[true,false,false,true]