While you receive html content through the function "preg_match_all", the special char is not displayed correctly, how to resolve this?

I am extracting the html content using the code below,

preg_match_all('/<div class="content">(.*?)<\/div>/s', $str, $matches);
echo $matches[1][0];

The content is selected correctly, but some special char whit text does not display correctly, as

"response to what?" show as "the answer to what?"

but it doesn’tdisplayed, but it does not matter. and some blanck space mapping as Â

How to solve this problem..?

+5
source share
2 answers

You have problems with unicode, try adding this as the first line in the script:

header('Content-Type: text/html; charset=utf-8');
+2
source

first add this line to your code ... (top)

   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+1
source

All Articles