Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you apply utf8_encode() 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 forceUTF8().</p> <p>You dont need to know what the encoding of your strings is. It can be Latin1 (iso 8859-1) or UTF8, or the string can have a mix of the two. forceUTF8() 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>$utf8_string = forceUTF8($utf8_or_latin1_or_mixed_string); $latin1_string = forceLatin1($utf8_or_latin1_or_mixed_string); </code></pre> <p>I've included another function, fixUFT8(), wich will fix every UTF8 string that looks garbled. </p> <p>Usage:</p> <pre><code>$utf8_string = fixUTF8($garbled_utf8_string); </code></pre> <p>Examples:</p> <pre><code>echo fixUTF8("Fédération Camerounaise de Football"); echo fixUTF8("Fédération Camerounaise de Football"); echo fixUTF8("FÃÂédÃÂération Camerounaise de Football"); echo 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 converted theese into a static class, and they live in Github now:</p> <p><a href="https://github.com/neitanod/forceutf8" rel="nofollow noreferrer">https://github.com/neitanod/forceutf8</a></p>
 

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