Home  >  Article  >  Backend Development  >  Enhanced version of htmlspecialchars function

Enhanced version of htmlspecialchars function

WBOY
WBOYOriginal
2016-07-25 09:07:17796browse
  1. //取消html代码
  2. function shtmlspecialchars($string) {
  3. if(is_array($string)) {
  4. foreach($string as $key => $val) {
  5. $string[$key] = shtmlspecialchars($val);
  6. }
  7. } else {
  8. $string = preg_replace(‘/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/’, ‘&\\1′,
  9. str_replace(array(‘&’, ‘”‘, ‘<’, ‘>’), array(‘&’, ‘"’, ‘<’, ‘>’), $string));
  10. }
  11. return $string;
  12. }
  13. ?>
复制代码


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