strip_tags($str) 去掉 HTML 及 PHP 的標(biāo)記。本函式和 fgetss() 有著相同的功能
PHP清除html、css、js格式并去除空格的PHP函數(shù)
function cutstr_html($string, $sublen)
{
$string = strip_tags($string);
$string = preg_replace ('/\n/is', '', $string);
$string = preg_replace ('/ | /is', '', $string);
$string = preg_replace ('/ /is', '', $string);
preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $string, $t_string);
if(count($t_string[0]) - 0 > $sublen) $string = join('', array_slice($t_string[0], 0, $sublen))."…";
else $string = join('', array_slice($t_string[0], 0, $sublen));
return $string;
}
htmlspecialchars 將特殊字元轉(zhuǎn)成 HTML 格式
htmlentities 將所有的字元都轉(zhuǎn)成 HTML 字串
PHP截取字符串的函數(shù)代碼
function utf_substr($str,$len)
{
for($i=0;$i<$len;$i++)
{
$temp_str=substr($str,0,1);
if(ord($temp_str) > 127)
{
$i++;
if($i<$len)
{
$new_str[]=substr($str,0,3);
$str=substr($str,3);
}
}
else
{
$new_str[]=substr($str,0,1);
$str=substr($str,1);
}
}
return join($new_str)."...";
}
//php sql防注入代碼
function GetSafeSQL($str)
{
$str = str_replace("and","",$str);
$str = str_replace("execute","",$str);
$str = str_replace("update","",$str);
$str = str_replace("count","",$str);
$str = str_replace("chr","",$str);
$str = str_replace("mid","",$str);
$str = str_replace("master","",$str);
$str = str_replace("truncate","",$str);
$str = str_replace("char","",$str);
$str = str_replace("declare","",$str);
$str = str_replace("select","",$str);
$str = str_replace("create","",$str);
$str = str_replace("delete","",$str);
$str = str_replace("insert","",$str);
$str = str_replace("'","",$str);
$str = str_replace("%","",$str);
$str = str_replace("&","",$str);
$str = str_replace("--","",$str);
$str = str_replace("<","",$str);
$str = str_replace(">","",$str);
$str = str_replace(" ","",$str);
$str = str_replace("or","",$str);
$str = str_replace("=","",$str);
$str = str_replace(";","",$str);
return $str;
}
// 去掉過濾html標(biāo)簽
//--------------------------
//--------------------------
function GetNoHTMLString($content)
{
$content = preg_replace("/<a[^>]*>/i", "", $content);
$content = preg_replace("/<\/a>/i", "", $content);
$content = preg_replace("/<p[^>]*>/i", "", $content);
$content = preg_replace("/<\/p>/i", "", $content);
$content = preg_replace("/<span[^>]*>/i", "", $content);
$content = preg_replace("/<\/span>/i", "", $content);
$content = preg_replace("/<html[^>]*>/i", "", $content);
$content = preg_replace("/<\/html>/i", "", $content);
$content = preg_replace("/<div[^>]*>/i", "", $content);
$content = preg_replace("/<\/div>/i", "", $content);
$content = preg_replace("/<img[^>]*>/i", "", $content);
$content = preg_replace("/<script[^>]*>/i", "", $content);
$content = preg_replace("/<\/script>/i", "", $content);
$content = preg_replace("/<!--[^>]*-->/i", "", $content);//注釋內(nèi)
$content = preg_replace("/style=.+?['|\"]/i",'',$content);//去除樣式
$content = preg_replace("/class=.+?['|\"]/i",'',$content);//去除樣式
$content = preg_replace("/id=.+?['|\"]/i",'',$content);//去除樣式
$content = preg_replace("/lang=.+?['|\"]/i",'',$content);//去除樣式
$content = preg_replace("/width=.+?['|\"]/i",'',$content);//去除樣式
$content = preg_replace("/height=.+?['|\"]/i",'',$content);//去除樣式
$content = preg_replace("/border=.+?['|\"]/i",'',$content);//去除樣式
$content = preg_replace("/face=.+?['|\"]/i",'',$content);//去除樣式
$content = preg_replace("/face=.+?['|\"]/",'',$content);//去除樣式 只允許小寫 正則匹配沒有帶 i 參數(shù)
return $content;
}
//對(duì)字符串進(jìn)行HTML過濾顯示
function _html($_string) {
if (is_array($_string)) {
foreach ($_string as $_key => $_value) {
$_string[$_key] = _html($_value); //這里采用了遞歸,如果不理解,那么還是用htmlspecialchars
}
} else {
$_string = htmlspecialchars($_string);
}
return $_string;
}
隱藏IP最后一位
function hideIP($ip) {
$res = strrpos($ip,'.');
$tmp = substr($ip,0,$res);
return $tmp.".*";
}
//mysql按時(shí)間查詢
SQL語句: Select * From user Where DATE_FORMAT(birthday,'%m-%d') >= '06-03' and DATE_FORMAT(birthday,'%m-%d') <= '07-08';
%W 星期名字(Sunday……Saturday)
%D 有英語前綴的月份的日期(1st, 2nd, 3rd, 等等。)
%Y 年, 數(shù)字, 4 位
%y 年, 數(shù)字, 2 位
%a 縮寫的星期名字(Sun……Sat)
%d 月份中的天數(shù), 數(shù)字(00……31)
%e 月份中的天數(shù), 數(shù)字(0……31)
%m 月, 數(shù)字(01……12)
%c 月, 數(shù)字(1……12)
%b 縮寫的月份名字(Jan……Dec)
%j 一年中的天數(shù)(001……366)
%H 小時(shí)(00……23)
%k 小時(shí)(0……23)
%h 小時(shí)(01……12)
%I 小時(shí)(01……12)
%l 小時(shí)(1……12)
%i 分鐘, 數(shù)字(00……59)
%r 時(shí)間,12 小時(shí)(hh:mm:ss [AP]M)
%T 時(shí)間,24 小時(shí)(hh:mm:ss)
%S 秒(00……59)
%s 秒(00……59)
%p AM或PM
%w 一個(gè)星期中的天數(shù)(0=Sunday ……6=Saturday )
%U 星期(0……52), 這里星期天是星期的第一天
%u 星期(0……52), 這里星期一是星期的第一天
%% 一個(gè)文字“%”。
php格式化mysql時(shí)間值
<?php echo date('Y-m-d',strtotime($rows['createdate'])); ?>