有用的php函式

2021-04-15 11:26:58 字數 1715 閱讀 1505

一 檔案靜態化

檔案讀取函式

//檔案讀取函式

function php_read($file_name)

fclose($fd);

return $buf;

}如果知道的是檔案的連線位址的話

$fileaddress="http://localhost/filename.html";(檔案所在的位址)

function php_read($

fileaddress

else

echo $content;

}檔案寫入函式

//建立目錄

$article_path="article";

if(!file_exists($article_path))

}//檔案寫入函式

function php_write($file_name,$data,$method="wb")

上面的寫入函式同樣是可以由file_put_contents("$filename",'$contents')來代替的

靜態頁面生成函式

//靜態頁面生成函式

function phptohtm($filefrom,$fileto,$u2u=1)else

php_write($fileto,$data);

return true;

}二 顯示客戶端ip與伺服器ip

在php 中用 $_server["remote_addr"] 來取得客戶端的 ip 位址 但如果客戶端是使用**伺服器來訪問 那取到的就是**伺服器的 ip 位址 要想透過**伺服器取得客戶端的真實 ip 位址 就要使用 $_server["http_x_forwarded_for"] 來讀取 但並不是每個**伺服器都能用

$_server["http_x_forwarded_for"] 來讀取客戶端的真實 ip 有些用此方法讀取到的仍然是**伺服器的 ip 

取得客戶端ip的函式  $_server['romote_addr']

取得伺服器端ip的函式  $_server['server_addr']

三 $_server預定義變數詳解

']=/test.php    //根路徑後的

四 函式歸納

1 date_default_timezone_set('asia/shanghai');  設定時區

2 set_include_path  設定需要匯入檔案的路徑,參見zendframework,中的應用

3 get_object_vars 返回由物件屬性呢組成的關聯陣列

php遇到的有用的函式

header location chdir 改變目錄 basename file 當前檔名稱 strpos strrpos stripos strripos substr empty isset realpath 獲取絕對路徑 set exception handler 函式 使用者定義的異常處理函...

php,幾個有用的函式介紹

strtr 函式轉換字串中 陣列中特定的字元。arr array hello hi world earth echostrtr hello world arr 輸出 hi earththe file put contents writes a string to a file.file put co...

5個有用的php陣列操作函式

1 修改一維陣列裡面某乙個鍵值對的key的名稱 修改陣列裡面某個key的名字 function array change key input,key,replace key 2 刪除一維陣列裡面某個值 刪除陣列裡面的某個值 function array delete input,value 3 刪除...