PHP How to convert strings from DomCrawler to UTF-8

I have some data that I collect using DomCrawler and save it in an array, but it looks like it fails when it comes to special characters like è, à, ï etc.

As an example, I get èinstead èwhen I return the result.

When I save my results in a .json file, I get the following: \u00c3\u00a8 My goal is to save a special character in a .json file.

I tried to code it, but it seems I do not want to get the result.

$html = file_get_contents($url);
$crawler = new Crawler($html);

$h1 = $crawler->filter('h1');
$title = $h1->text();
$title = mb_convert_encoding($title, "HTML-ENTITIES", "UTF-8");

Is there a way to show my special characters?

Thank you so much!

+4
source share
1 answer

HTML, , ISO-8859-1. , DOM UTF-8 addHTMLContent:

$html = file_get_contents($url);
$crawler = new Crawler;
$crawler->addHTMLContent($html, 'UTF-8');
0

All Articles