doudiemei2013 2013-08-06 06:32
浏览 118
已采纳

从UTF-8 XML数据中删除不可见的字符

I am consuming an XML feed which contains a great deal of whitespace. When I echo out the raw feed, it looks as though the columns of the tabled data are properly formatted with just the white space.

I have tried many regex patterns to remove it, to only allow visible characters, trim, chop, utf-8 encode/decode, nothing is touching it. It's like it is laughing in my face when I echo out a value and see this:

string(17) "72"

Opened the data in Notepad++ with show all characters on, and it simply shows it as spaces. I am at a loss of where to go with this.

I did recieve the following error:

simplexml_load_string(): Entity: line 265: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xB0 0x43 0x20 0x74
  • 写回答

3条回答 默认 最新

  • dongpin3794 2013-08-06 06:37
    关注

    I just found this regex (untested)

    $xml_data = preg_replace("/>\s+</", "><", $xml_data);
    

    If you are using the xml parser, I think you can use the 'XML_OPTION_SKIP_WHITE' option referenced here: http://php.net/manual/en/function.xml-parser-set-option.php

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部