Asked  7 Months ago    Answers:  5   Viewed   30 times
<tag>
????? ?
</tag>

When I try to get the content of the following code using DOMDocument functions, it returns something like:

ÐÐ»ÐµÐºÑ Ðœ

I've tried setting DOMDocument encoding to different values (UTF-8, ISO-8859-1), using mb_convert_encoding, iconv and utf8_encode but without success.

How can I get "????? ?" instead of "ÐÐ»ÐµÐºÑ Ðœ" ?

EDIT: The input is coming from a page loaded with curl. When I output the page content to my browser, the characters are displayed correctly (so I doubt the input is the problem).

 Answers

59

Try:

$string = file_get_contents('your-xml-file.xml');
$string = mb_convert_encoding($string, 'utf-8', mb_detect_encoding($string));
// if you have not escaped entities use
$string = mb_convert_encoding($string, 'html-entities', 'utf-8'); 
$doc = new DOMDocument();
$doc->loadXML($string);
Wednesday, March 31, 2021
 
mattltm
answered 7 Months ago
86

Using libxml_use_internal_errors(true); suppresses error output but builds a continuous log of errors which is appended to on each loop. Either disable the internal logging and suppress PHP warnings, or clear the internal log on each loop iteration like this:

<?php
libxml_use_internal_errors(true);
while(true){
 $dom = new DOMDocument();
 $dom->loadHTML(file_get_contents('ebay.html'));
 unset($dom);
 libxml_use_internal_errors(false);
 libxml_use_internal_errors(true);
 echo memory_get_peak_usage(true) . "rn"; flush();
}
?>
Wednesday, March 31, 2021
 
millenomi
answered 7 Months ago
87

Try for subject:

$sub = '=?UTF-8?B?'.base64_encode($subject).'?=';

And then:

mail($to, $sub, $message, $headers);
Wednesday, March 31, 2021
 
akohout
answered 7 Months ago
20

I use this:

function replaceSpecial($str){
$chunked = str_split($str,1);
$str = ""; 
foreach($chunked as $chunk){
    $num = ord($chunk);
    // Remove non-ascii & non html characters
    if ($num >= 32 && $num <= 123){
            $str.=$chunk;
    }
}   
return $str;
} 
Wednesday, March 31, 2021
 
akohout
answered 7 Months ago
39

Here's an earlier answer of mine about the same problem, try that: How to display a mysql table data in another language properly in php

Saturday, May 29, 2021
 
Sujith
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :