php在字符串的第n个字符串上添加不同的字符串

I found this code that replaces the second char or index of a string.

$string="blah";
$string=substr_replace($string,"",1,1);

but instead, i want to have a string added on the second index of a string.

$input = 'asdf';
$string_to_be_added = 'eee';
$output = 'aseeedf';

what should be changed in my code?

You're passing incorrect arguments. The correct syntax and order is:

substr_replace ($string, $replacement, $start, $length);

You need the string to be added to the second position, so supply 2 as the start parameter:

$newstring = substr_replace($input, $string_to_be_added, 2, 0);

Output:

string(7) "aseeedf"