CKTIS / PHP
substr_replace()
Zastępuje zakres bajtów wskazany pozycją.
Wersja: PHP 8.4; repository runtime, production runtime not attested
Składnia
substr_replace(array|string $string, array|string $replace, array|int $offset, array|int|null $length = null): string|arrayZastępuje zakres bajtów wskazany pozycją. Długość zero oznacza wstawienie, null zastępuje do końca, ujemny offset liczy wstecz. Dla tablicy napisów można podać oddzielne początkowe pozycje, długości i zamienniki.
Sygnatura
substr_replace(array|string $string, array|string $replace, array|int $offset, array|int|null $length = null): string|array
Wynik przykładu
["AB-CD","ABX",["Cat","Dog"]]
Przykłady
<?php
echo json_encode([substr_replace("ABCD","-",2,0),substr_replace("ABCD","X",-2),substr_replace(["cat","dog"],["C","D"],[0,0],[1,1])]);
Wynik
["AB-CD","ABX",["Cat","Dog"]]