5

次のコードを実行します。

$page = '<p>Ä</p>';
$DOM = new DOMDocument;
$DOM->loadHTML($page);
echo 'source:'.$page;
echo 'dom: '.$DOM->getElementsByTagName('p')->item (0)->textContent;

そして、次を出力します。

ソース: Ä

ドム: ×

テキストが DOMDocument を介して送信されると、エンコーディングが壊れる理由がわかりません。

4

2 に答える 2

8

Here's a workaround that adds the proper encoding via meta header:

$DOM->loadHTML('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . $page);

I'm not sure if that's the actual character set you're trying to use, but adjust where necessary

See also: domdocument character set issue

于 2012-10-01T16:17:41.073 に答える
6
于 2012-10-01T16:17:36.443 に答える