Base de connaissancesCentre d’examen
FRFrançais
Choisir la langue13

CKTIS / PHP

str_starts_with()

Teste un préfixe d’octets exact au début en respectant la casse.

Version : PHP 8.4; repository runtime, production runtime not attested

Syntaxe

str_starts_with(string $haystack, string $needle): bool

Teste un préfixe d’octets exact au début en respectant la casse. Un motif vide est préfixe de toute chaîne, un motif non vide ne correspond pas à une entrée vide. Une espace initiale compte et n’est pas retirée.

Signature

str_starts_with(string $haystack, string $needle): bool

Sortie de l’exemple

[true,false,false,true]

Exemples

<?php
echo json_encode([str_starts_with("ID-2","ID-"),str_starts_with(" ID-2","ID-"),str_starts_with("","ID"),str_starts_with("","")]);

Résultat

[true,false,false,true]

Sources