Search code examples
phputf-8windows-1252

How to convert Windows-1252 characters to values in php?


We have several database fields that contain Windows-1252 characters:

an example pain— if you’re

Those values map to the desired values from this list:

http://www.i18nqa.com/debug/utf8-debug.html

I've tried various permutations of htmlentites, mb_detect_encoding, uft8_decode, etc, but have not yet been able to transform those values to:

an example pain — if you're

How can I transform these characters to their listed values in php?


Solution

  • You can use mb_convert_encoding

    $str = "an example pain— if you’re";
    $str = mb_convert_encoding($str, "Windows-1252", "UTF-8");
    echo $str;
    //an example pain— if you’re
    

    DEMO:
    http://ideone.com/NsIb5x