PHP常用函式 帶中文注釋

2021-05-25 21:31:22 字數 3617 閱讀 1402

<?

//獲取ip

function getip()

//時間的增加(還可以改進成時分秒都可以增加,有時間再補上)

function dateadd($date, $int, $unit = "d")

//計算出給出的日期是星期幾

function getweekday($date)

?>

<?

//檢查日期是否合法日期

function check_date($date)

return false;

} //檢查時間是否合法時間

function check_time($time)

return false;

} //時間比較函式,返回兩個日期相差幾秒、幾分鐘、幾小時或幾天

function datediff($date1, $date2, $unit = "")

$time1 = strtotime($date1);

$time2 = strtotime($date2);

if ($time1 && $time2) 

return (float)($time1 - $time2) / $dividend;

return false;

} ?>

php重定向

<?

//方法一:header("location: index.php");

//方法二:echo "window.location ="$php_self";"; 

//方法三:echo "";

?>

獲取訪問者瀏覽器

<?

function browse_infor() }

if (ereg("mozilla",$agent) && !ereg("msie",$agent)) 

if (ereg("mozilla",$agent) && ereg("opera",$agent))

if (ereg("mozilla",$agent) && ereg("msie",$agent))

if ($browser!="")

else

return $browseinfo;

} //呼叫方法$browser=browseinfo() ;直接返回結果

?>

獲取訪問者作業系統

<?

function osinfo()

elseif (eregi('win 9x',$agent) && strpos($agent, '4.90'))

elseif (eregi('win',$agent) && ereg('98',$agent))

elseif (eregi('win',$agent) && eregi('nt 5.0',$agent))

elseif (eregi('win',$agent) && eregi('nt',$agent))

elseif (eregi('win',$agent) && eregi('nt 5.1',$agent))

elseif (eregi('win',$agent) && ereg('32',$agent))

elseif (eregi('linux',$agent))

elseif (eregi('unix',$agent))

elseif (eregi('sun',$agent) && eregi('os',$agent))

elseif (eregi('ibm',$agent) && eregi('os',$agent))

elseif (eregi('mac',$agent) && eregi('pc',$agent))

elseif (eregi('powerpc',$agent))

elseif (eregi('aix',$agent))

elseif (eregi('hpux',$agent))

elseif (eregi('netbsd',$agent))

elseif (eregi('bsd',$agent))

elseif (ereg('osf1',$agent))

elseif (ereg('irix',$agent))

elseif (eregi('freebsd',$agent))

if ($os=='') $os = "unknown";

return $os;

} //呼叫方法$os=os_infor() ;

?>

//頁面快速轉向

<?

function turntopage($url="index.php",$info = "頁面轉向中...",$second=2)

return $hash;

} ?>

擷取一定長度的字串(該函式對gb2312使用有效)

<?

function wordscut($string, $length ,$sss=0)

for($i = 0; $i < $length; $i++) else

} return $wordscut.$addstr;

} return $string;

} ?>

//取得客戶端ip位址

<?

function getip()

?>

//判斷郵箱位址

<?

function checkemail($inaddress)

?>

分頁(兩個函式配合使用)

<?

function getpage($sql,$page_size=20)

function showbar($string="")

",$table);

$table = str_replace("","",$table); //php開源**

//去掉 html 標記 

$table = preg_replace("'<[///!]*?[^<>]*?>'si","",$table);

//去掉空白字元  

$table = preg_replace("'([/r/n])[/s]+'","",$table); 

$table = str_replace(" ","",$table);

$table = str_replace(" ","",$table);

$table = explode('', $table); 

array_pop($table);

foreach ($table as $key=>$tr) ', $tr);

array_pop($td); 

$td_array = $td;

} return $td_array;

} ?>

//返回字串中的所有單詞 $distinct=true 去除重複

<?

function split_en_str($str,$distinct=true)

sort($match[1]);

return $match[1];

} ?>

php擷取中文函式

擷取中文字元函式一 function cutstr string,length,dot charset utf 8 string str replace array array string strcut if strtolower charset utf 8 elseif 194 t t 223 ...

python 常用函式 ,帶輸出

1.取絕對值 abs abs 1 12.判斷所有內容是否都為真,是則返回true,非0即為真 all all 1,2,3 true all 0,2,3 false 3.判斷至少有乙個為真則返回true any any 0,0,1 true any 0,0,0 false 4.將十進位制轉化為二進位制...

php 採集常用函式 PHP常用採集函式

獲取所有鏈結內容和位址function getallurl code 獲取所有的位址 function getimgsrc code else fnum if fnum fnum 0 return fnum 去除html標記 function text2html txt isu r n txt re...