带有口音的字母显示在我的本地服务器上,但不显示在我的prod服务器上

时间:2014-10-03 17:05:42

标签: php laravel utf-8

在我的本地服务器上通过 MAMP 进行模拟,它会正确返回所有带重音的字母。 在我的生产服务器主机上 Dreamhost ,它会在此菱形的钻石中返回一个问号:â..

当我在我的Production Server上发出ajax请求时,我无法用JSON编码我的对象,因为它无法将我的字符串值识别为UTF-8编码(必须使用utf8_encode)。

我该怎么做才能解决这个问题?我找不到任何答案。

修改

我正在使用数据库为自己使用 utf8_unicode_ci ,所有表和原始字符串都是字符串类型。

请求Prod的标题

Accept:application/json, text/plain, *
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Cookie:laravel_session=eyJpdiI6ImFlNW5ZbmljWkcwcVM5XC9QdGxtZGZZVUxwK2tZNWZiYlwvYkdPSHdIcGxkcz0iLCJ2YWx1ZSI6IjE0RU51M1ZYVlwvM1U2QlR0MjFuOGo2WXVtUXFLQkJzWFVRbjBoV2thVmZzSWNaOXozQVJXQjRHZFNjMkp6b0Z0RjZoV1wvN2Y0bVwvdThpbkpwdFdcL0U4Zz09IiwibWFjIjoiODE1YzJhZDYwMWU4MDkwMjM1YTg2NjU1MGVkMmZiNGZiOWVlNWJhODc3ZTAyOGVlOGEzMjJhMDRlYzdjNmIxMiJ9; _ga=GA1.2.474837750.1412291587; _gat=1; Hm_lvt_aff7c47cb709e5851f8459e1408034c6=1412291588; Hm_lpvt_aff7c47cb709e5851f8459e1408034c6=1412432225
Host:www.mywebsite.com
Referer:http://www.mywebsite.com
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36
X-Requested-With:XMLHttpRequest

Prod的响应标题

Connection:Keep-Alive
Content-Encoding:gzip
Content-Type:text/html; charset=UTF-8
Date:Sat, 04 Oct 2014 14:17:05 GMT
Expires:Sat, 04 Oct 2014 14:17:06 GMT
Keep-Alive:timeout=2, max=99
Server:Apache
Transfer-Encoding:chunked
Vary:Accept-Encoding,User-Agent

从本地请求标头

Accept:application/json, text/plain, *
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Cookie:SQLiteManager_currentLangue=2; laravel_session=eyJpdiI6Im1lSnNnTFRjbnFqU29NVVdoT1V2M0lqSlY1SncxdTF0MVwvd2QrNzFLT21jPSIsInZhbHVlIjoidzdxb2k2Zld3aUhJaWRKZnhIeFJ1XC9zeG1uaTNGblRETEkwd04ra1FjK0F5Y0JxQk1CbW9jdDNpcU01NE1BQlgxSmN6MXFDRkVBbjhRRFBqRXdpcFVRPT0iLCJtYWMiOiI2MmE2YTIzNDBiNjE5NjM2ZGE5NjNhOGQxZWU5YjIyMTZmNjI3NWVlNjdhYzY1ZDY1OGE5OTE3NTgyM2I5YzM2In0%3D
Host:localhost
Referer:http://localhost/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36
X-Requested-With:XMLHttpRequest

本地响应标头

Connection:Keep-Alive
Content-Encoding:gzip
Content-Type:text/html; charset=UTF-8
Date:Sat, 04 Oct 2014 14:16:49 GMT
Expires:Sat, 04 Oct 2014 14:16:50 GMT
Keep-Alive:timeout=5, max=99
Server:Apache/2.2.26 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.6 PHP/5.5.14 mod_ssl/2.2.26 OpenSSL/0.9.8za DAV/2 mod_perl/2.0.8 Perl/v5.18.2
Transfer-Encoding:chunked

提前谢谢。

1 个答案:

答案 0 :(得分:1)

我有setLocale('fr_FR')现在我setLocale('fr_FR.UTF8')它解决了问题!

对于任何AJAX请求,Laravel不再使用json_encode()抛出任何错误。 我的strftime函数返回带有重音的每个字母的正确字符。