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?

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

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();

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.