CKTIS / PHP
substr()
Extrait une tranche d’octets. Un offset négatif compte depuis la fin, une longueur négative exclut des octets finaux.
Version : PHP 8.4; repository runtime, production runtime not attested
Syntaxe
substr(string $string, int $offset, ?int $length = null): stringExtrait une tranche d’octets. Un offset négatif compte depuis la fin, une longueur négative exclut des octets finaux. Sans longueur ou avec null, prend le reste. Un départ après la fin donne la chaîne vide, un départ avant le début est ramené à zéro. La coupe peut scinder un caractère UTF-8.
Signature
substr(string $string, int $offset, ?int $length = null): string
Sortie de l’exemple
["CD","BCD","","AB","c3"]
Exemples
<?php
echo json_encode([substr("ABCDE",-3,2),substr("ABCDE",1,-1),substr("ABCDE",9),substr("ABC",-9,2),bin2hex(substr("\u{00E9}",0,1))]);
Résultat
["CD","BCD","","AB","c3"]