Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird char (�) appears after doing html_entity_decode

In a separate YML file i have :
flags: [<img src="/images/cms_bo/icons/english.png" alt="English"/>]

When i call this into my code, it's not interpreted, so i used html_entity_decode.

It works but i have only 1 strange char just before my image :

<?php echo html_entity_decode($form['lang']->render()); ?>

All my files are UTF8 encoded. Do you have an idea on what i've missed to solve this problem ?

PS:

      public static function getI18nCulturesForChoice()
  {
      return array_combine(self::getI18nCultures(), self::getI18nCulturesFlags());
  }
like image 229
sf_tristanb Avatar asked Aug 05 '26 23:08

sf_tristanb


2 Answers

Try using html_entity_decode($form['lang']->render(),ENT_QUOTES, "UTF-8");

like image 140
whlk Avatar answered Aug 08 '26 15:08

whlk


Prior to PHP 5.3.3, the default character set for html_entity_decode was ISO-8859-1! If you're working with UTF-8, you will need to use the third argument to the function to tell it to deal with UTF-8 instead of assuming ISO-8859-1.

This is blindly assuming you're using an older version of PHP.

If you are using a newer version of PHP, consider using iconv with the //IGNORE//TRANSLIT flags to try and remove any bad UTF-8 sequences before passing the string into html_entity_decode.

like image 27
Charles Avatar answered Aug 08 '26 17:08

Charles