drfkl66684 2013-01-10 10:33
浏览 97
已采纳

PHP echo中的奇怪字符导致无效的JSON

I am using echo in php to return a database request. When trying to decode the result in Flash I get errors telling me of unexpected characters. When I looked at the output in the browser it looked fine. But when I copied the contents (Select All -> Copy) and then ran the text through a script in php I saw a lot of strange characters. This explains why the JSON decoding fails, but how do I get rid of the strange characters?

Test script to check the string

    $string = str_split($string);
    echo '<pre>';
    print_r($string);
    echo '<pre>';

Result:

    [0] => ï
        [1] => »
        [2] => ¿
        [3] => ï
        [4] => »
        [5] => ¿
        [6] => ï
        [7] => »
        [8] => ¿
...
  • 写回答

2条回答 默认 最新

  • dongwei1855 2013-01-10 11:10
    关注

    I found the solution after reading this answer. The problem was that my PHP files were saved with UTF-8 encoding with BOM. Saving the files with UTF-8 encoding solved my problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法