How can I replace a character in the middle of a string? how can I replace a character in the middle of a string? For example, replace & nbsp; fdsfdsfdsjkww with: f ************ w for example: & nbsp; replace points with: deduct *** for example: & nbsp; replace the deduction points with *** s. For example, & nbsp; tt: replace the deduction points: t ***** s how to replace the character in the middle of a string
How to replace the character in the middle of a string?
For example, fdsfdsfdsjkww
Replace with: f *********** w
For example, the score is deducted by Jin Ximin.
Replace with: buckle *** people
For example, the score is deducted by Jin Ximin s.
Replace with: *** s
For example, tt points are deducted by Jin Ximin s.
Replace with: t ***** s
Share:
------ Solution --------------------
$ Str = 'TT points deducted from Kingdom s ';
Function hide_repalce ($ str, $ code = 'utf-8 '){
Mb_internal_encoding ($ code );
$ Len = mb_strlen ($ str );
Return mb_substr ($ str, 0, 1). str_repeat ('*', $ len-2). mb_substr ($ str, $ len-1, 1 );
}
Echo hide_repalce ($ str );