substr_replace()


string substr_replace ( string $string, string $replace, int $start [ , int $length ] )

Description

substr_replace() replaces a copy of string delimited by the start and (optionally) length parameter with the string given in replacement

※ available F/W version : all

Parameters

Return values

Returns the result string

Example

<?php
$str = "Hello PHPoC!";
$ret = substr_replace($str, "Hi", 0, 5); echo "$ret\r\n";    // OUTPUT: Hi PHPoC!
$ret = substr_replace($str, "Hi", -12, 5); echo "$ret\r\n";  // OUTPUT: Hi PHPoC!
$ret = substr_replace($str, "Hi", 0, -7); echo "$ret\r\n";   // OUTPUT: Hi PHPoC!
$ret = substr_replace($str, "Hi", 6); echo "$ret\r\n";       // OUTPUT: Hello Hi

$str = "";
$ret = substr_replace($str, "Hi", 6); echo "$ret\r\n";       // OUTPUT: Hi
?>

See also

str_repeat() / strpos() / str_replace() / substr()

Remarks

This function is identical to the PHP group’s substr() function but it doesn’t support array.