Home > php教程 > php手册 > body text

解析php入库和出库

WBOY
Release: 2016-06-13 11:44:42
Original
1406 people have browsed it

数据放入数据库和取出来显示在页面需要注意什么
入库时
$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;
}
?>

 

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!