作者:WINGZERO哥哥 | 来源:互联网 | 2014-08-20 22:05
php函数代码如下:functionihtmlspecialchars($string){if(is_array($string)){foreach($stringas$key=>$val){$string[$key]=ihtmlspecialchars($val);}}else{开源代码phpfensi.com
php函数代码如下:
- function ihtmlspecialchars($string)
- {
- if(is_array($string))
- {
- foreach($string as $key => $val)
- {
- $string[$key] = ihtmlspecialchars($val);
- }
- } else
- {
- $string = preg_replace('/&((#(d{3,5}|x[a-fa-f0-9]{4})|[a-za-z][a-z0-9]{2,5});)/', '&\1',
- str_replace(array(&#39;&&#39;, &#39;"&#39;, &#39;<&#39;, &#39;>&#39;), array(&#39;&&#39;, &#39;"&#39;, &#39;<&#39;, &#39;>&#39;), $string));
- }
- return $string;
- }
实例代码如下:
- $str = &#39;;
- echo ihtmlspecialchars( $str );
- echo &#39;
&#39;;
- echo htmlspecialchars ($str );
两个结果完全相同,所以个人觉得自php自带的函数高效于用户自定义函数.