json_encode encodes strings with Unicode (copyright) character as null?
我在JSON编码特殊字符方面遇到麻烦。这些字符通常显示在我的计算机,记事本,浏览器甚至数据库中。但是,它们不进行JSON编码。示例如下:
1 2 3 4 |
site.com之后的版权符号是使JSON字符串回显为
我的多字节设置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | php -e phpinfo.php | grep mb Configure Command => './configure' '--enable-bcmath' '--enable-calendar' '--enable-dbase' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--enable-sockets' '--enable-zip' '--prefix=/usr/local' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-bz2' '--with-curl=/opt/curlssl/' '--with-curlwrappers' '--with-freetype-dir=/usr' '--with-gd' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libdir=lib64' '--with-libexpat-dir=/usr' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mhash=/opt/mhash/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl=/usr' '--with-openssl-dir=/usr' '--with-pcre-regex=/opt/pcre' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-pic' '--with-png-dir=/usr' '--with-sqlite=shared' '--with-ttf' '--with-xmlrpc' '--with-xpm-dir=/usr' '--with-zlib' '--with-zlib-dir=/usr' xmlrpc_error_number => 0 => 0 mbstring Multibyte string engine => libmbfl mbstring extension makes use of"streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1. mbstring.detect_order => no value => no value mbstring.encoding_translation => Off => Off mbstring.func_overload => 0 => 0 mbstring.http_input => pass => pass mbstring.http_output => pass => pass mbstring.internal_encoding => no value => no value mbstring.language => neutral => neutral mbstring.strict_detection => Off => Off mbstring.substitute_character => no value => no value |
我想避免保存诸如
以UTF-8格式编码数据,然后再将其传递给json_encode函数
1 2 3 4 | <? $array['copyright_str'] = utf8_encode("Copyright site.com ? 2011-2012"); echo json_encode($array); ?> |
我正在使用
用大量UTF-8符号对数据进行编码
1 |
,效果很好。我用它来编码各种语言:阿拉伯语,中文,泰语,立陶宛语,德语,法语,西班牙语等。所有这些语言都有不同的独特符号。哦,我还没有尝试编码雪人? :)
在
之前使用
1 2 3 4 5 | <? $array['copyright_str'] ="Copyright site.com ? 2011-2012"; $array['copyright_str'] = urlencode($array['copyright_str']); echo json_encode($array); ?> |