简体   繁体   中英

PHP / MySQL special characters issue

I'm facing an issue with the special characters. I'm taking information from a DB in MSSQL which returns in php a value which may contain specials characters like "à é ö ü" etc. In my sample, I will use the city name of Zürich and when I try to insert this information into a MySQL database, I get the following error :

"Incorrect string value: '\\xFCrich ...' for column..."

so, I've done the following but it still showing the same error message:

$arrSearch = array('\xE4','\xF6','\xFC','\xC4','\xD6','\xDC','\xDF');
$arrReplace = array('ä','ö','ü','Ä','Ö','Ü','ß',);
$City=str_replace($arrSearch, $arrReplace, $City);

If I do an echo of $City, I get the following : Z rich (rectangular block)

I've tried as well hex2bin() but I just get a white page and nothing is inserted into Database. FYI, DB collation is in utf8mb4_general_ci and setlocale(LC_ALL, 'en_EN') is set in php file. All php files are encoded into UTF8 and chatset is set as follow : mysql_set_charset('utf8mb4',$link);

I must admit, I'm a bit lost. Does anyone has a clue on how to fix this? Thanks.

EDIT: The server hosting this app is running under 2008R2/IIs 7.5 and I've found this KB by Microsoft. I'll try the hotfix and the registry modification but it didnt work. http://support.microsoft.com/kb/2277918/

将字符集设置为utf8。

Ok got it! Was so stupid.... I'm using FPDF with that insertion and to show special characters properly in FPDF, I had to set an iconv('UTF-8', $charset, $_REQUEST['City']); Sorry and thanks again for assistance! now works like a charm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM