PHP: Problems converting “’” character from ISO-8859-1 to UTF-8

后端 未结 2 887
别那么骄傲
别那么骄傲 2021-02-04 20:16

I\'m having some issues with using PHP to convert ISO-8859-1 database content to UTF-8. I am running the following code to test:

// Connect to a latin1 charset d         


        
相关标签:
2条回答
  • 2021-02-04 21:01

    this will solve your problem, supposing that your page header charset is utf-8:

    // Opens a connection to a MySQL server
    $connection = mysql_connect ($server, $username, $password);
    $charset = mysql_client_encoding($connection);
    $flagChange = mysql_set_charset('utf8', $connection);
    echo "The character set is: $charset</br>mysql_set_charset result:$flagChange</br>";
    
    0 讨论(0)
  • 2021-02-04 21:08

    U+2019 RIGHT SINGLE QUOTATION MARK is not a character in ISO-8859-1. It is a character in windows-1252, as 0x92. The actual ISO-8859-1 character 0x92 is a rarely-used C1 control character called "Private Use 2".

    It is very common to mislabel Windows-1252 text data with the charset label ISO-8859-1. Many web browsers and e-mail clients treat the MIME charset ISO-8859-1 as Windows-1252 characters in order to accommodate such mislabeling but it is not standard behaviour and care should be taken to avoid generating these characters in ISO-8859-1 labeled content.

    It appears that this is what's happening here. Change "ISO-8859-1" to "windows-1252".

    0 讨论(0)
提交回复
热议问题