Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you apply <code>utf8_encode()</code> to an already UTF8 string it will return a garbled UTF8 output.</p> <p>I made a function that addresses all this issues. It´s called <code>Encoding::toUTF8()</code>.</p> <p>You don't need to know what the encoding of your strings is. It can be Latin1 (iso 8859-1), Windows-1252 or UTF8, or the string can have a mix of them. <code>Encoding::toUTF8()</code> will convert everything to UTF8.</p> <p>I did it because a service was giving me a feed of data all messed up, mixing UTF8 and Latin1 in the same string.</p> <p>Usage:</p> <pre><code>require_once('Encoding.php'); use \ForceUTF8\Encoding; // It's namespaced now. $utf8_string = Encoding::toUTF8($utf8_or_latin1_or_mixed_string); $latin1_string = Encoding::toLatin1($utf8_or_latin1_or_mixed_string); </code></pre> <p>Download:</p> <p><a href="https://github.com/neitanod/forceutf8" rel="noreferrer">https://github.com/neitanod/forceutf8</a></p> <p>Update:</p> <p>I've included another function, <code>Encoding::fixUFT8()</code>, which will fix every UTF8 string that looks garbled. </p> <p>Usage:</p> <pre><code>require_once('Encoding.php'); use \ForceUTF8\Encoding; // It's namespaced now. $utf8_string = Encoding::fixUTF8($garbled_utf8_string); </code></pre> <p>Examples:</p> <pre><code>echo Encoding::fixUTF8("Fédération Camerounaise de Football"); echo Encoding::fixUTF8("Fédération Camerounaise de Football"); echo Encoding::fixUTF8("FÃÂédÃÂération Camerounaise de Football"); echo Encoding::fixUTF8("Fédération Camerounaise de Football"); </code></pre> <p>will output:</p> <pre><code>Fédération Camerounaise de Football Fédération Camerounaise de Football Fédération Camerounaise de Football Fédération Camerounaise de Football </code></pre> <p>Update: I've transformed the function (<code>forceUTF8</code>) into a family of static functions on a class called <code>Encoding</code>. The new function is <code>Encoding::toUTF8()</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload