doudiemei2013 2013-08-06 14: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 14: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条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘