CKTIS / PHP
substr_replace()
Nahradí rozsah bajtů určený pozicí.
Verze: PHP 8.4; repository runtime, production runtime not attested
Syntaxe
substr_replace(array|string $string, array|string $replace, array|int $offset, array|int|null $length = null): string|arrayNahradí rozsah bajtů určený pozicí. Nulová délka vloží, null nahradí až do konce a záporný offset počítá zpět. Pro pole řetězců lze zadat pozice, délky a náhrady po jednotlivých položkách.
Signatura
substr_replace(array|string $string, array|string $replace, array|int $offset, array|int|null $length = null): string|array
Výstup příkladu
["AB-CD","ABX",["Cat","Dog"]]
Příklady
<?php
echo json_encode([substr_replace("ABCD","-",2,0),substr_replace("ABCD","X",-2),substr_replace(["cat","dog"],["C","D"],[0,0],[1,1])]);
Výsledek
["AB-CD","ABX",["Cat","Dog"]]