php常用的基本函數__函數

來源:互聯網
上載者:User

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 函數名(參數  //可寫可不寫){
 
 //要執行的功能流程及操作
 return "返回的值";  //可返回可不返回
}

函數是可以嵌套使用的,就是函數可以調用函數(但:自己調用自己很容易產生死循

環)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.