違法なことは何もしていないのですが、何か問題があるのでしょうか?
if (strtolower($matches[1]) != 'utf-8') {
var_dump($matches[1]);
$xml = iconv($matches[1], 'utf-8', $xml);
$xml = str_replace('encoding="'.$matches[1].'"', 'encoding="utf-8"', $xml);
}
以下は私のデバッグ/エラーです。
string(12) "windows-1252"
Notice (8): iconv() [http://php.net/function.iconv]: Detected an illegal character in input string [APP/models/sob_form.php, line 16]
上記のコードが確かに16行目であることを確認しました。
しかし、受け入れられた回答を使用した場合でも、入力文字列中の文字が音訳できない場合には、PHP Noticeが表示されます。
<?php
$cp1252 = '';
for ($i = 128; $i < 256; $i++) {
$cp1252 .= chr($i);
}
echo iconv("cp1252", "utf-8//TRANSLIT", $cp1252);
PHP Notice: iconv(): Detected an illegal character in input string in CP1252.php on line 8
Notice: iconv(): Detected an illegal character in input string in CP1252.php on line 8
そこで、音訳できない文字を無視する IGNORE を使用する必要があります。
echo iconv("cp1252", "utf-8//IGNORE", $cp1252);