Search code examples
phpcurlencodingeuro

Euro symbol encoding - PHP


I've tried a lot of different things and can't get the euro symbol to show. I'm using cURL to parse a page. The page is encoded in ISO-8859-1

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

There's a euro symbol on the page and when I use

$curl_scraped_page = curl_exec($ch);

I just get a black diamond with a question mark inside.

I've seen a lot of questions and answers on this site that were related but they didn't really work.

EDIT : I've tried to use the following:

$curl_scraped_page = preg_replace('/charset=(.*)"/', 'charset="UTF-8"', $curl_scraped_page);

and

$curl_scraped_page = iconv('iso-8859-1', 'UTF-8', $curl_scraped_page);

and

$curl_scraped_page = utf8_encode(curl_exec($ch));

I guess another question is, to display the euro sign, do I need to use UTF-8 or ISO-8859-1?

EDIT2 : I've tried this:

echo "Encoding is $enc";
echo iconv($enc, "ISO-8859-1", $curl_scraped_page);

The result was:

Encoding is ISO-8859-1

but there were still no euro symbols. When I view the source of the page, it still shows the diamond question marks but when I click 'View' on the browser and change it to ISO-8859-1, the euro symbols appear. So is it a browser issue?


Solution

  • I set cURL to parse in ISO-8859-1 encoding, before I do the cURL parse

    header('Content-Type: text/html; charset=iso-8859-1');
    $curl_scraped_page = curl_exec($ch);
    

    This means that it takes the Euro symbol in as it is on the page. Then when I echo the content with the Euro symbol, I don't have to worry about the encoding because I think it automatically formats to whichever encoding I'm using.