CKTIS / PHP
substr()
Izreže razpon bajtov. Negativen odmik šteje od konca, negativna dolžina izloči končne bajte.
Različica: PHP 8.4; repository runtime, production runtime not attested
Sintaksa
substr(string $string, int $offset, ?int $length = null): stringIzreže razpon bajtov. Negativen odmik šteje od konca, negativna dolžina izloči končne bajte. Brez dolžine ali z null vzame ostanek. Začetek za koncem vrne prazen niz, položaj pred začetkom pa se omeji na nič. Rez lahko razdeli znak UTF-8.
Podpis
substr(string $string, int $offset, ?int $length = null): string
Izhod primera
["CD","BCD","","AB","c3"]
Primeri
<?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))]);
Rezultat
["CD","BCD","","AB","c3"]