Reputation: 1888
How can I insert text into a PHP string at a specific point without overwriting anything?
Upvotes: 4
Views: 440
Reputation: 61
Simple, use substr()
:
$str_a = "foo bar";
$str_b = substr($str_a, 0, 3) . ' baz' . substr($str_a, 3);
Upvotes: 0
Reputation: 1888
Use substr_replace() with a length value of 0.
CODE:
substr_replace("abcdefgh","-bbbb-",3,0);
The output of the above will be "abc-bbbb-defgh"
Upvotes: 3