欧美日韩一区二区三区四区不卡,日韩欧美视频一区二区三区四区,久久精品欧美一区二区三区不卡,国产精品久久久乱弄

咨詢電話:186 7916 6165 咨詢電話:186 7916 6165 (微信同號)    在線QQ:181796286
NEWS BLOG ·
學無止境
關注開優網絡 關注前沿
PHP Web開發之靜態方法
PHP Web開發之操作XML

PHP Web開發之常用方法

發表日期:2015-09-05    文章編輯:南昌開優網絡    瀏覽次數:4529    標簽:PHP應用

strip_tags($str) 去掉 HTML 及 PHP 的標記。本函式和 fgetss() 有著相同的功能 
PHP清除html、css、js格式并去除空格的PHP函數 
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 將特殊字元轉成 HTML 格式
htmlentities 將所有的字元都轉成 HTML 字串 

PHP截取字符串的函數代碼
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標簽
//--------------------------
//--------------------------
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);//注釋內
$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 參數  
return $content;
}

//對字符串進行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按時間查詢
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 年, 數字, 4 位   
%y 年, 數字, 2 位   
%a 縮寫的星期名字(Sun……Sat)   
%d 月份中的天數, 數字(00……31)   
%e 月份中的天數, 數字(0……31)   
%m 月, 數字(01……12)   
%c 月, 數字(1……12)   
%b 縮寫的月份名字(Jan……Dec)   
%j 一年中的天數(001……366)   
%H 小時(00……23)   
%k 小時(0……23)   
%h 小時(01……12)   
%I 小時(01……12)   
%l 小時(1……12)   
%i 分鐘, 數字(00……59)   
%r 時間,12 小時(hh:mm:ss [AP]M)   
%T 時間,24 小時(hh:mm:ss)   
%S 秒(00……59)   
%s 秒(00……59)   
%p AM或PM   
%w 一個星期中的天數(0=Sunday ……6=Saturday )   
%U 星期(0……52), 這里星期天是星期的第一天   
%u 星期(0……52), 這里星期一是星期的第一天   
%% 一個文字“%”。 
php格式化mysql時間值
<?php echo date('Y-m-d',strtotime($rows['createdate'])); ?>
主站蜘蛛池模板: 河池市| 大关县| 丰原市| 无极县| 恩施市| 达尔| 通渭县| 江孜县| 山阳县| 天峻县| 德昌县| 河源市| 栾城县| 江孜县| 龙州县| 浦东新区| 宕昌县| 牡丹江市| 吉水县| 太白县| 休宁县| 拉萨市| 台前县| 龙门县| 襄汾县| 武城县| 大足县| 多伦县| 新沂市| 抚远县| 襄汾县| 东台市| 临西县| 梁山县| 凤阳县| 洛浦县| 东兴市| 沙洋县| 昌吉市| 黄冈市| 鸡泽县|