How do I replace a character in the middle of a string?
For example: Fdsfdsfdsjkww
Replaced by: f**********w
For example: deduction of Kim Simin
To be replaced by: Buckle * * * min
For example: Deduction of Kim Simin s
To be replaced by: Buckle ****s
For example: TT buckle Kim Simin s
Replaced by: t*****s
Reply to discussion (solution)
Replace (string1, start, string2,n,m)
It's garbled, see? Garbled to see what your code is set the correct encoding
$string = ' Fdsfdsfdsjkww ';
Echo substr ($string, 0, 1). ' '. substr ($string, $sLeng -1,1);
It's garbled, see?
If you use utf8-encoding, the encoding of the source file and the encoding of the output display are used Utf-8 Simple point of
$string = ' Fdsfdsfdsjkww '; Echo substr_replace ($string, Str_repeat (' * ', strlen ($string)-2), 1, strlen ($string)-2);
Note the length of the problem, in different codes, the Chinese and English bytes will not be the same, more to calculate the length of the pair, or it will appear garbled
$string = ' Fdsfdsfdsjkww '; Echo substr_replace ($string, Str_repeat (' * ', strlen ($string)-2), 1, strlen ($string)-2);
This is relatively simple.
Substr_replace? To replace a substring of a string
String
The input string.
Replacement
The replacement string.
Start
If start is a positive number, the substitution starts at the start position of the string.
If start is a negative number, the substitution starts at the bottom-starting position of string.
Length
If this parameter is set and is a positive number, the length of the substring that is substituted in the string is represented. If set to negative, it represents the number of characters at the end of the substring to be replaced at the ends of the string. If this parameter is not provided, it defaults to strlen (string). Of course, if length is 0, then the function is to insert replacement into the start position of string