3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <!DOCTYPE html> <head> <meta charset="EUC-JP"> </head> <body> <h1>テスト文書</h1> <p>これはテスト用のHTMLです。EUC-JPと宣言しているのにShift_JISでエンコードされています。</p> </body> HTML; $html = mb_convert_encoding($html, 'SJIS-win'); // そのまま読み込むと当然文字化けする $doc = \Dom\HTMLDocument::createFromString($html, \Dom\HTML_NO_DEFAULT_NS); $xpath = new \Dom\XPath($doc); $node = $xpath->query("//h1")->item(0); var_dump($node->textContent); // 一度UTF-8にしてから、第3引数でエンコードを固定 $html = mb_convert_encoding($html, 'UTF-8', 'SJIS-win'); $doc = \Dom\HTMLDocument::createFromString($html, \Dom\HTML_NO_DEFAULT_NS, 'UTF-8'); $xpath = new \Dom\XPath($doc); $node = $xpath->query("//h1")->item(0); var_dump($node->textContent);
Output for git.master_jit, git.master
string(21) "�e�X�g���" string(15) "テスト文書"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
56.4 ms | 405 KiB | 5 Q