0

I have a file writed in french language and I want to load it with DomDocument to parse it

$this->doc = new \DomDocument('1.0', 'UTF-8');

$url = $this->file_get_contents_utf8('/file.html');

$array = Array();
$internalErrors = libxml_use_internal_errors(true);

@$this->doc->loadHTML($url);
$str = $this->doc->saveHTML($this->doc);

$xpath = new \DOMXpath($this->doc);

I saved the file with UTF8 and Tried to load it by forcing UTF-8 but it do not shows special chars like the accents

Mairie d'Amb**éri**

should be :

Mairie d'Ambé...

Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • I explain the issue with `DOMDocument` using ISO-8859-1 character encoding by default and how modern frameworks use a workaround to output UTF-8 in this answer: https://stackoverflow.com/a/76196866/1456201 – Jim May 11 '23 at 14:33
  • 1
    You didn't show us what `file_get_contents_utf8` does, which seems kind of important. – IMSoP May 11 '23 at 20:24

0 Answers0