Home  >  Article  >  Backend Development  >  解析php入库和出库_php技巧

解析php入库和出库_php技巧

WBOY
WBOYOriginal
2016-05-17 08:58:38910browse

数据放入数据库和取出来显示在页面需要注意什么
入库时
$str=addslashes($str);
$sql=\"insert into `tab` (`content`) values(\'$str\')\";
出库时
$str=stripslashes($str);
显示时
$str=htmlspecialchars(nl2br($str)) ;

//--标题,名字等字段入库处理(去首尾空格)
functiontrans_string_trim($str){
$str=trim($str);
$str=eregi_replace("'","''",$str);
$str=stripslashes($str);
return$str;
}
//--文章入库处理,即textarea字段;
functiontrans_string($str){
$str=eregi_replace("'","''",$str);
$str=stripslashes($str);
return$str;
}
//--从库中显示在表单中;在text中以trans转换,在textarea中,无需转换,直接显示
//--显示在WEB页面,过滤HTML代码;包括链接地址
functiontrans($string){
$string=htmlspecialchars($string);
$string=ereg_replace(chr(10),"
",$string);
$string=ereg_replace(chr(32),"",$string);
return$string; 
}
//--显示在WEB页面,不过滤HTML代码;
functiontrans_web($string){
$string=ereg_replace(chr(10),"
",$string);
$string=ereg_replace(chr(32),"",$string);
return$string; 
}
//--显示在WEB页面,过滤HTML代码及头尾空格,主要用于显示用户昵称
functiontrans_trim($string){
$string=trim($string);
$string=htmlspecialchars($string);
$string=ereg_replace(chr(10),"
",$string);
$string=ereg_replace(chr(32),"",$string);
return$string; 
}
//--显示在span中;
functiontrans_span($string){
$string=ereg_replace(chr(10),"\n",$string);
$string=ereg_replace(chr(32),"",$string);
$string=ereg_replace('"',""",$string);
return$string; 
}
//--在WEB上显示cookie,过滤html
functiontrans_cookie($str){
$str=trans($str);
$str=stripslashes($str);
$str=eregi_replace("''","'",$str);
return$str;
}
?>

 

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