Home > php教程 > php手册 > php html过滤代码(预定义的字符转换为 HTML 实体)

php html过滤代码(预定义的字符转换为 HTML 实体)

WBOY
Release: 2016-06-13 10:11:38
Original
1138 people have browsed it

//把一些预定义的字符转换为 HTML 实体 以及在预定义字符前加上反斜杠,包括 单引号、双引号、反斜杠、NULL,以保护数据库安全

//把一些预定义的字符转换为 html 实体 以及在预定义字符前加上反斜杠,包括 单引号、双引号、反斜杠、null,以保护数据库教程安全

function d_htmlspecialchars($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = d_htmlspecialchars($val);
}
} else {
$string = str_replace('&', '&', $string);
$string = str_replace('"', '"', $string);
$string = str_replace(''', ''', $string);
$string = str_replace(' $string = str_replace('>', '>', $string);
$string = preg_replace('/&(#d;)/', '&1', $string);
}
return $string;
}

//

function d_addslashes($string, $force = 0) {
if(!$globals['magic_quotes_gpc'] || $force) {
if(is_array($string)) {
foreach($string as $key => $val) $string[$key] = d_addslashes($val, $force);
}
else $string = addslashes($string);
}
return $string;
}
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template