I need to replace a char in a string.
$s1='123456789';
$s2='abcdefghi';
$p=4; // position of char in $s1 to use for replacing (0 is first char)
$s2 = ???? ; // code
In the end $s2 must be ‘abcd5fghi’
What would be fastest method?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you only have single-byte characters:
Otherwise, in case of multi-byte characters, you will probably need to use
mb_substr: