The mb_substitute_character Function
The mb_substitute_character
function allows you to set the character that will be used
to replace invalid byte sequences in multibyte strings. As a
parameter, you can pass an integer (character code) or the string "none"
to disable
substitution, or "long"
to output the numeric representation of the invalid character.
Syntax
mb_substitute_character([mixed $substitute_char]): mixed
Example
Let's set the substitution character as a question mark:
<?php
mb_substitute_character('?');
echo mb_convert_encoding("\x80", "UTF-8", "ISO-8859-1");
?>
Code execution result:
'?'
Example
Let's get the current substitution character:
<?php
$res = mb_substitute_character();
var_dump($res);
?>
Code execution result (character code '?'
):
63
Example
Let's disable the substitution of invalid characters:
<?php
mb_substitute_character("none");
echo mb_convert_encoding("\x80", "UTF-8", "ISO-8859-1");
?>
Code execution result:
''