今天开发遇到一个php curl取数据乱码问题

不是gzip也不是编码设置问题

最后有一同事判断为utf8+bom保存数据原因,懒得深入了解utf8+bom,仅做记录

[root@centos5 ~]# curl -s http://phone.10086.cn/ | head -1 | hexdump -C
00000000  ef bb bf 3c 21 44 4f 43  54 59 50 45 20 68 74 6d  |...<!DOCTYPE htm|
00000010  6c 20 50 55 42 4c 49 43  20 22 2d 2f 2f 57 33 43  |l PUBLIC "-//W3C|
00000020  2f 2f 44 54 44 20 58 48  54 4d 4c 20 31 2e 30 20  |//DTD XHTML 1.0 |
00000030  54 72 61 6e 73 69 74 69  6f 6e 61 6c 2f 2f 45 4e  |Transitional//EN|
00000040  22 20 22 68 74 74 70 3a  2f 2f 77 77 77 2e 77 33  |" "http://www.w3|
00000050  2e 6f 72 67 2f 54 52 2f  78 68 74 6d 6c 31 2f 44  |.org/TR/xhtml1/D|
00000060  54 44 2f 78 68 74 6d 6c  31 2d 74 72 61 6e 73 69  |TD/xhtml1-transi|
00000070  74 69 6f 6e 61 6c 2e 64  74 64 22 3e 0d 0a        |tional.dtd">..|
0000007e
[root@centos5 ~]# curl -s http://www.test.com/pay1/notify_url | head -1 | hexdump -C                      
00000000  ef bb bf 31                                       |...1|
00000004
##这个就是utf8+bom后取得的数据,多了一个头
[root@centos5 ~]# curl -s http://www.test.com/ | head -1 | hexdump -C 00000000 ef bb bf 3c 21 44 4f 43 54 59 50 45 20 68 74 6d |...<!DOCTYPE htm| 00000010 6c 20 50 55 42 4c 49 43 20 22 2d 2f 2f 57 33 43 |l PUBLIC "-//W3C| 00000020 2f 2f 44 54 44 20 58 48 54 4d 4c 20 31 2e 30 20 |//DTD XHTML 1.0 | 00000030 54 72 61 6e 73 69 74 69 6f 6e 61 6c 2f 2f 45 4e |Transitional//EN| 00000040 22 20 22 68 74 74 70 3a 2f 2f 77 77 77 2e 77 33 |" "http://www.w3| 00000050 2e 6f 72 67 2f 54 52 2f 78 68 74 6d 6c 31 2f 44 |.org/TR/xhtml1/D| 00000060 54 44 2f 78 68 74 6d 6c 31 2d 74 72 61 6e 73 69 |TD/xhtml1-transi| 00000070 74 69 6f 6e 61 6c 2e 64 74 64 22 3e 0d 0a |tional.dtd">..|

从curl转hexdump格式后看,正常的utf8是以|...<!DOCTYPE htm|开头

utf8+bom保存的文件curl得出的是

00000000  ef bb bf 31                                       |...1|

备忘

详细参考地址:http://huoding.com/2011/05/14/78

最后当然是让对方技术人员将文件转成utf8保存即解决问题

posted on 2013-06-28 18:05  cycsa  阅读(1164)  评论(0编辑  收藏  举报