スペルが同じでなくても、文字列を比較して名前を一致させる必要があります。たとえば、 DÉSIRÉ-Smith
DesireeDesireesmith
またはDesi'ree Smith
したがって、PHP-CLIを使用してコマンドラインで完全に機能する次のアプローチがありました。
<?
class Alike {
static function convertAlike($string) {
// in case the first and last name or two first names are mixed up
$parts = preg_split('/[\s\-\.\_]/', $string, -1, PREG_SPLIT_NO_EMPTY);
sort($parts);
$string = implode($parts);
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string); // transliterate
$string = strtolower($string); // lowercase
$string = preg_replace('/[^a-z]/','',$string); // remove everything but a-z
$string = preg_replace('{(.)\1+}','$1',$string); // remove duplicate chars
return $string;
}
static function compareAlike($string1,$string2) {
return (strcmp(Alike::convertAlike($string1),Alike::convertAlike($string2)) === 0) ? true : false;
}
}
echo Alike::convertAlike("DÉSIRÉ-Smith").PHP_EOL; // desiresmith
echo Alike::convertAlike("Desireesmith").PHP_EOL; // desiresmith
echo Alike::convertAlike("Desi'ree Smith").PHP_EOL; // desiresmith
echo Alike::convertAlike("René Röyßeå likes special characters ½ € in ©").PHP_EOL; // reneroysealikespecialcharacterseurinc
var_dump(Alike::compareAlike("DÉSIRÉ-Smith","Desireesmith")); // true
var_dump(Alike::compareAlike("Desireesmith","Desi'ree Smith")); // true
var_dump(Alike::compareAlike("summer","winter")); // false
?>
ただし、モジュールとしてServer version: Apache/2.2.14 (Ubuntu)
実行PHP Version 5.3.2-1ubuntu4.2
されている私の Web サイトでは、常に疑問符だけが表示されます。面白いことに、この行でエラーが発生する必要があります
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string); // transliterate
その後、音訳されていないすべての文字を見ることができますが、ASCII文字に置き換えられるべきだった文字は疑問符になります。
入力/出力文字列エンコーディングとiconv内部、入力および出力エンコーディング設定、およびロケール設定の可能なすべての組み合わせを試しました。chmod -R 777 /usr/lib/gconv を実行して、作業ディレクトリに移動しました。
ただし、このバグがメーリングリストで報告されているのを見ました: http://bugs.php.net/bug.php?id=44096
[2010-06-07 21:22 UTC] icovt at yahoo dot com
mod_php iconv() is not working properly if your apache is chrooted and you do not
have the content of /usr/lib/gconv/ folder into your relative chroot path (i.e.
/your/chroot/path/usr/lib/gconv/).
You can simply do:
cp /usr/lib/gconv/* /your/chroot/path/usr/lib/gconv/
... and re-try.
This was a fix for me, hope this could save time for somebody else.
P.S. Btw, initially iconv() called from command line (using php cli) was OK.
www-data ユーザーが /var/www/ の自宅にいることを試してみたところ、最終的にフォルダー /var/www/usr/lib/gconv/ と /var/www/myproject/usr/lib/gconv になりました/
参考までに、正しいエンコーディングが確実に渡されるようにするためのエンコーディング検出とトランスコーディング機能がありましたが、utf8文字列を入力すれば必要ないため、わかりやすくするためにそれらを削除しました...
何か案は?