admin管理员组

文章数量:1550527

报错如下

This page contains the following errors:

error on line 36083 at column 16: Input is not proper UTF-8, indicate encoding ! Bytes: 0x08 0xE5 0x85 0xB3

Below is a rendering of the page up to the first error.

原因:XML 规范不支持如下字符
#x00 - #x08 (ASCII 0 - 8)
#x0B - #x0C (ASCII 11 - 12)
#x0E - #x1F (ASCII 14 - 31)

解决方法

php

function removeIllegalChar($content)
{
    if (is_string($content)) {
        $content = preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/", "", $content);
    } else if (is_array($content)) {
        foreach ($content as $k => $v) {
            $content[$k] = removeIllegalChar($v);
        }
    }
    return $content;
}

java 

public static String removeIllegalChar(String content) {
    if (content == null || "".equals(content)) {
        return content;
    }

    return content.replaceAll("[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]", "");
}

 

本文标签: 报错浏览器文件XMLASCII