Home  >  Article  >  Backend Development  >  Convert php characters to HTML entities

Convert php characters to HTML entities

高洛峰
高洛峰Original
2016-11-29 15:12:241557browse

function d_htmlspecialchars($string) { 
 if(is_array($string)) { 
  foreach($string as $key => $val) { 
   $string[$key] = d_htmlspecialchars($val); 
  }//开源代码phpfensi.com 
 } else { 
  $string = str_replace('&', '&', $string); 
  $string = str_replace('"', '"', $string); 
  $string = str_replace(''', ''', $string); 
  $string = str_replace(&#39;<&#39;, &#39;&lt;&#39;, $string); 
  $string = str_replace(&#39;>&#39;, &#39;&gt;&#39;, $string); 
  $string = preg_replace(&#39;/&amp;(#d;)/&#39;, &#39;&1&#39;, $string); 
 } 
 return $string; 
}


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