Home > Backend Development > PHP Tutorial > Filter illegal characters in xml

Filter illegal characters in xml

巴扎黑
Release: 2016-11-23 10:40:24
Original
1814 people have browsed it

 xml里面的,虽然可以放各种各样的特殊字符,但还是有些字符放不进去,因为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]", "");
Copy after login



Php代码

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


Related labels:
xml
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template