程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> PHP中常用的函數

PHP中常用的函數

編輯:PHP綜合
<?
class useful{
function formatnumber(num){
return number_format(num, 2, ".", ","); function formatstring(string = ""){
string = preg_replace(array("/ /", "/ /"), array("&nbsp;", "&nbsp;&nbsp;"), string);
return nl2br(string); function formatcontent(text){
trans = get_html_translation_table(Html_SPECIALCHARS);
trans = array_flip(trans);
text = strtr(text, trans);
//text = str_replace("\n", "<br>", text);
//text = str_replace(" ", "&nbsp;", text);
return text; function bitsize(num){
if(!preg_match("/^[0-9]+/", num)) return 0;
return num > 1024 ? (num/1024 > 1024 ? round(num/1024/1024, 2)." Mb" : round(num/1024, 2)." Kb") : num." 字節"; function add_s(&array){
foreach(array as key=>value){
if(!is_array(value)){
array[key]=addslashes(value);
}else{
this->add_s(array[key]); } function specialHtml(&array){
if(is_array(array)){//數組處理
foreach(array as key=>value){
if(!is_array(value)){
array[key]=Htmlspecialchars(value);
}else{
this->specialHtml(array[key]); }
}else{
array = Htmlspecialchars(array); }
function msubstr(str, start, len) {
tmpstr = "";
strlen = start + len;
for(i = 0; i < strlen; i++) {
if(ord(substr(str, i, 1)) > 0xa0) {
tmpstr .= substr(str, i, 2);
i++;
} else
tmpstr .= substr(str, i, 1); return tmpstr; function alert_msg(msg, direct = "0"){
switch(direct){
case '0'://提示
script = "";
case '1'://提示刷新返回
script = "location.href=\""._SESSION["HTTP_REFERER"]."\";";
break;
case '2'://提示返回
script = "history.back();";
break;
default://提示轉向指定頁面
script = "location.href=\"".direct."\";"; echo "<script language='Javascript'>window.alert('".msg."');".script."</script>";
exit; function aweek(gdate = "", first = 0){
if(!gdate) gdate = date("Y-m-d");
w = date("w", strtotime(gdate));//取得一周的第幾天,星期天開始0-6
dn = w ? w - first : 6;//要減去的天數
st = date("Y-m-d", strtotime("gdate -".dn." days"));
en = date("Y-m-d", strtotime("st +6 days"));
return array(st, en);//返回開始和結束日期 function checkurl(){ //echo "referer:"._SESSION['HTTP_REFERER'];
if(!isset(_SESSION['HTTP_REFERER'])) {
header("location: index.PHP");
exit; urlar = parse_url(_SESSION['HTTP_REFERER']); if(_SERVER["HTTP_HOST"] != urlar["host"]) {
header("location: index.PHP");
exit; }
function readfiles(file){
tdata = "";
fp = fopen(file, "r"); if(filesize(file) <= 0) return; while(data = fread(fp, filesize(file))){
tdata .= data; fclose(fp);
return tdata; }
?>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved