0

Hi. I use a fuction to retrieve some information from a remote site:

$dom = new DOMDocument;
@$dom->loadHTMLFile($url);
$page_content = $dom->saveHTML();

When I echo the content, some characters appear like 'á'. I have tried many things from the internet, but nothing helped.

Is there a solution?

2
Contributors
2
Replies
14
Views
4 Years
Discussion Span
Last Post by eburlea
0

When I echo the content, some characters appear like 'á'. I have tried many things from the internet, but nothing helped.

What is your default language? Meaning is your page encoded in UTF-8 or something else?

If it's UTF-8 then used this:

From this

$dom = new DOMDocument;
@$dom->loadHTMLFile($url);
$page_content = $dom->saveHTML();

Add this:

$url = file_get_contents('your-xml-file.xml');
$url = mb_convert_encoding($url, 'utf-8', mb_detect_encoding($string));
$url = mb_convert_encoding($url, 'html-entities', 'utf-8'); 
$dom = new DOMDocument();
$dom->loadHTML($url);
$page_content = $dom->saveHTML();
1

Thank you for the answer.

Your first line provides exactly what I was looking for:

$page_content = file_get_contents($url);

Now all characters are as I need them to be.

Thanks again!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.