I want to insert a character after the first character in a word using PHP like this, ID: R-CDA12345 to first character in this ID serves as the type of an item so I can easily know where it is from.
I tried a method like this,
$id_number = "RCDA12345";
$char = explode(' ', $id_number);
$char[1] = "-";
var_export($char);
It’s not working -_-
2
Answers
You can do that with
substr
:Or with
substr_replace
:Which can also insert string in string by given offset and with given length (3rd and 4th parameters)
You may try this with
substr_replace()
: