Function name: mb_substitute_character()
Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7
Usage: The mb_substitute_character() function is used to set or get code points for alternative characters.
Syntax: mb_substitute_character([int $substitute_character = -1])
parameter:
- $substitute_character (optional): The code point of the substitute character to be set. If this parameter is not passed in, the code point of the current substitute character will be returned. The default value is -1, which means no substitution is performed.
Return value:
- If the $substitute_character parameter is passed in, the code point of the previous substitute character is returned.
- If no argument is passed in, the code point of the current substitute character is returned.
Example 1: Set the code point of the substitute character to 0xFFFD (Unicode substitute character) and return the previous code point.
$previous = mb_substitute_character(0xFFFD); echo "之前的替代字符代码点为:" . $previous; // 输出:之前的替代字符代码点为:63
Example 2: Get the code point for the current substitute character.
$substitute = mb_substitute_character(); echo "当前的替代字符代码点为:" . $substitute; // 输出:当前的替代字符代码点为:-1
Notes:
- Alternative characters are characters used when dealing with illegal characters. When characters that cannot be converted are encountered, substitutes are used for substitution.
- The code point for the alternative character must be a valid Unicode code point, usually an integer. The commonly used alternative character code point is 0xFFFD (Unicode alternative character).
- If the code point of the substitute character is set to -1, it means that no substitution is performed, but a warning or error is thrown.
- This function is only valid for PHP versions that use mbstring extensions. If the extension is not enabled, the function will be unavailable.