Home  >  Article  >  php教程  >  php 过滤字符串函数

php 过滤字符串函数

WBOY
WBOYOriginal
2016-06-13 11:18:09919browse

 

function addslashes_str($str){
$str=addslashes($str);
$str=str_replace($str,";",';');
return $str;
}
function stripslashes_str($str){
$str=stripslashes($str);
$str=str_replace($str,';',";");
return $str;
}
?>

 
 chop(); //除去字符串右边空格
 trim(); //除去字符串中所有空格
 ltrim(); //除去字符串左边空格 
 htmlspecialchars(); //转换'$','"',''为相应的html实体
 htmlentities(); //转换所有html标记为相应的html实体
 array explode(string separator, string str); //分割字符串
 string implode(string separator, array arr); //连接字符串
 strtoupper(); strtolower(); //转换大小写
 ucfirst(); //只转换第一个字符为大写
 ucwords(); //转换每个words的第一个字母为大写
iconv()
php内码转换函数,同上
因为iconv()在转换gb2312时的bug,所以要这样处理
iconv( "utf-8", "gb2312//ignore" , $str)

mb_convert_encoding()
php的内码转换函数
版本(php 4 >= 4.0.6, php 5)
这个函数可以将各种编码互相转换
mb_convert_encoding($str,"gb2312", "utf-8");


mysql教程_real_escape_string()
定义:函数转义 sql 语句中使用的字符串中的特殊字符。
语法: mysql_real_escape_string(string,connection)
说明:本函数将 string 中的特殊字符转义,并考虑到连接的当前字符集,因此可以安全用于 mysql_query()。
 ?>


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