1--TEST-- 2Dom\HTMLDocument::createFromString() with overrideEncoding 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8try { 9 Dom\HTMLDocument::createFromString(file_get_contents(__DIR__ . '/gb18030_without_charset.html'), overrideEncoding: 'nonexistent'); 10} catch (ValueError $e) { 11 echo $e->getMessage(), "\n"; 12} 13 14// The override encoding matches with the document encoding attribute 15$dom = Dom\HTMLDocument::createFromString(file_get_contents(__DIR__ . '/gb18030_without_charset.html'), overrideEncoding: 'GB18030'); 16var_dump($dom->documentElement->lastChild->textContent); 17var_dump($dom->charset); 18 19// The override encoding mismatches with the document encoding attribute 20$dom = Dom\HTMLDocument::createFromString(file_get_contents(__DIR__ . '/fallback_encoding.html'), overrideEncoding: 'Windows-1252'); 21var_dump($dom->documentElement->lastChild->textContent); 22var_dump($dom->charset); 23 24?> 25--EXPECT-- 26Dom\HTMLDocument::createFromString(): Argument #3 ($overrideEncoding) must be a valid document encoding 27string(20) " 28 Héllo, world! 29" 30string(7) "gb18030" 31string(1) " 32" 33string(12) "windows-1252" 34