php常用的基本函式

2021-05-21 17:37:25 字數 1929 閱讀 4266

php的函式分為系統函式,使用者函式

1,php函式不區分大小寫

函式原型:

返回型別 函式名稱(型別 引數)

2.1,系統函式中常用的數學函式

abs(eumber) 去絕對值

sin(float)  正弦計算sin(x)

cos(float) 余弦計算cos(x)

log(float) 自然對數計算

sqrt(float) 開平方根計算

log10(float) 10基底的對數

exp(float) 自然對數e的次方值

pow(float x,float y) 次方x的y次方

pi()  圓周率

rand([min],[max])    取隨機數

2.2 字串函式

strtolower()    字串轉為小寫

strtoupper()    字串轉為大寫

trim()        截去字串首尾空格

substr(string,start,[length])    取子串

strlen(string str)    取得字串長度

strpos(母串,待查字元,[offset])    尋找字串中某字元最先出現處

strcmp(str1,str2)    字串比較

2.3 檔案系統函式:

int filesize(string filename)    獲得檔案大小

int feof(int fp)        測試檔案指標是否指到檔案尾

int fopen(string filename,string mode)    開啟檔案或者url

int fclose(int fp)        關閉已開啟的檔案

string fread(int fp,int n)    讀取檔案n個位元組

string fgets(int fp,int n)    取得檔案指標所指的行(適合大檔案處理)

int fwrite(int fp,string string,int[n])    寫入檔案

int fputs(int fp,string str,int[n])    寫入檔案

int mkdir(string pathname,int mode)    建立目錄

int rmdir(string dirname)        刪除目錄

int rename(string oldname,string newname)    改名

2.4 網路函式:

int fsockopen(string hostname,int port,int[errno],string[errstr],int

[timeout])    開啟網路socket鏈結

string gethostbyname(string hostname)    dns查詢,返回ip**

array gethostbynamel(string hostname)    返回機器名稱的所有ip

2.5 mysql資料庫函式:

int mysql_connect(string[hostname][:port],string[username],string

[password]);    mysql伺服器連線

int mysql_select_db(string database_name,int[link_identifier]);    選擇乙個

資料庫int mysql_query(string query,int[link_identifier]);    執行sql串

int mysql_close(int[link_identifier]);    關閉mysql伺服器連線

2.6 自定義的函式

格式:function 函式名(引數  //可寫可不寫)

函式是可以巢狀使用的,就是函式可以呼叫函式(但:自己呼叫自己很容易產生死循

環)

php 基本函式

定義常數 獲取常數 常數不能定義兩次 初始化變數值 ini set display errors 1 獲取變數值。echo ini get display errors n 用php的 ob start 1 flush 重新整理緩衝區的內容,輸出。函式格式 flush 說明 這個函式經常使用,效率很...

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...

常用基本函式

1 清屏 clc 清除命令視窗 clear command window 清除命令視窗 clear 清除所有變數 clf 清除圖形 舊版本中可以使用 clg 2 隨機數生成 rand n 生成n階隨機方陣,隨機數範圍0 1 rand m,n 生成m n階的隨機矩陣,隨機數範圍0 1 randn n ...