Home  >  Article  >  Backend Development  >  Filter illegal characters in xml

Filter illegal characters in xml

巴扎黑
巴扎黑Original
2016-11-23 10:40:241781browse

 xml里面的608e66a17ec78840b88fe4ee8d0824c9,虽然可以放各种各样的特殊字符,但还是有些字符放不进去,因为xml允许的字符范围是"#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]",也就是说\x00-\x08,\x0b-\x0c,\x0e-\x1f这三组字符是不允许出现的。所以需要过滤一下,过滤的方法也很简单 

Java代码  

str = str.replaceAll("[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]", "");



Php代码  

function filterXmlStr($str)     
{     
  return preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/",'',$str);     
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn