Home > Backend Development > PHP Tutorial > Convert php characters to HTML entities

Convert php characters to HTML entities

高洛峰
Release: 2016-11-29 15:12:24
Original
1570 people have browsed it

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; 
}
Copy after login


Related labels:
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