CKTIS / PHP
substr_replace()
Remplace une plage d’octets choisie par position.
Version : 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|arrayRemplace une plage d’octets choisie par position. Longueur zéro insère, null remplace jusqu’à la fin et un offset négatif compte à rebours. Pour un tableau de chaînes on peut fournir positions, longueurs et remplacements par entrée.
Signature
substr_replace(array|string $string, array|string $replace, array|int $offset, array|int|null $length = null): string|array
Sortie de l’exemple
["AB-CD","ABX",["Cat","Dog"]]
Exemples
<?php
echo json_encode([substr_replace("ABCD","-",2,0),substr_replace("ABCD","X",-2),substr_replace(["cat","dog"],["C","D"],[0,0],[1,1])]);
Résultat
["AB-CD","ABX",["Cat","Dog"]]