0

In one part of my site, some accent characters (é,à...) are replaced by black question marks. It is for sure some encoding character but the thing is that everywhere the site displays well, except for the $html variable whose accent are corrupted and which is set this way

 $html = <<<EOF

<div>...
  <header>...
EOF;

What is weird is that on my local machine, everything goes well but on my remote machine, it is failing. For information, I correctly set this <meta charset="utf-8">

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
user1611830
  • 4,749
  • 10
  • 52
  • 89
  • Where the data come from? Are they from database or they are simple placed in content? – Marcin Nabiałek Jul 17 '14 at 09:43
  • @MarcinNabiałek no there's no data coming from database. I tried to put `header("Content-Type: text/plain; charset=ISO-8859-1");` inside the method that defines `$html` but it did not change – user1611830 Jul 17 '14 at 09:50
  • Have you tried to add `header("Content-Type: text/html; charset=UTF-8")` before displaying `$html` variable? I assume you simple `echo $html;` ? – Marcin Nabiałek Jul 17 '14 at 09:52
  • @MarcinNabiałek yes but it doesn't change anything... – user1611830 Jul 17 '14 at 10:00
  • You should then isolate some code and paste the whole code into the question – Marcin Nabiałek Jul 17 '14 at 10:02
  • @MarcinNabiałek if I put `var_dump($html)` inside my code, I see that the accent are not in utf8. Is there a way to convert this string to correct encoded one – user1611830 Jul 17 '14 at 10:06
  • IF the file is saved in editor in UTF-8 encoding there is no need to make any conversions. Do you save it in editor as UTF-8 file or you simple use for example notepad that doesn't save it as UTF-8 ? – Marcin Nabiałek Jul 17 '14 at 10:07
  • @MarcinNabiałek I use `phpstorm` ide and on my local it works perfectly fine. Btw, if I `mb_detect_encoding` my variable, I get `utf-8`. Weird, isn't it ? – user1611830 Jul 17 '14 at 10:10
  • @MarcinNabiałek btw, how can I check in which encoding the file was saved on my remote server ? – user1611830 Jul 17 '14 at 10:11
  • @MarcinNabiałek - get it, I ran on my remote `file -i myfile`, and I got `charset=iso-8859-1` ! – user1611830 Jul 17 '14 at 10:13
  • 1
    You can compare file size or compile file content using for example Total Commander synchronize option. And you can simple copy file from your server to localhost and try to open it in phpStorm to check if characters are displayed well. However without a file it's hard to say anything more. – Marcin Nabiałek Jul 17 '14 at 10:13
  • PHP offers several syntaxes to produce strings. I can't see any obvious reason why choosing one or another would alter your output encoding. I strongly suspect you'll get the same issue if you just type the text as-is, outside PHP blocks. – Álvaro González Jul 17 '14 at 10:17

0 Answers0