My puppyのブログ

学んだ事や作っているプログラムなどについて書いています。

(解決)Error: "Input is not proper UTF-8, indicate encoding !" using PHP's simplexml_load_string

1週間ほど前の話です。

PHPのsimplexml_load_string()を使ってYouTubeからxmlファイルをダウンロードしようとしたら失敗してしまいまして、「parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xED 0x6E 0x2C 0x20」の様なエラーが表示されたんですね。

このエラーをグーグルで検索したら、Stack Overflowの以下のページがヒットしました。

この中の回答にある以下のコードを使わせて頂いたところ、解決したので良かったです。

If you are sure that your xml is encoded in UTF-8 but contains bad characters, you can use this function to correct them :

$content = iconv('UTF-8', 'UTF-8//IGNORE', $content);

今後の為にこのブログにメモっておきますね。