Given the following code:
<?php
$mb_name = "湊崎 紗夏";
$tmp_mb_name = iconv('UTF-8', 'UTF-8//IGNORE', $mb_name);
if($tmp_mb_name != $mb_name) {
echo "tmp_mb_name: {$tmp_mb_name}\n";
echo "mb_name: {$mb_name}\n";
exit;
} else {
echo "no problem!\n";
}
I tested in 3v4l.org and it outputs no problem!
However, in php:7.4-fpm-alpine docker image, it outputs the following:
tmp_mb_name:
mb_name: 湊崎 紗夏
According to php.net:
If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded.
Why does $mb_name cannot be represented in UTF-8 in php alpine image?