PHP常用內建函數記憶(持更)

來源:互聯網
上載者:User

標籤:單詞   pad   add   and   ase   雙引號   boa   字串處理   echo   

<?php/** * 會話控制 *///開啟sessionsession_start();//建立session$_SESSION[‘name‘] = ‘admin‘;//刪除sessionunset($_SESSION[‘name‘]);sessoion_destroy();//建立cookiesetcookie(‘name‘, ‘value‘, time()+7*24*60*60); //7天//刪除cookiesetcookie(‘name‘, ‘value‘, time()-1);/** * 字串處理 *///移除字串兩邊的空白trim(‘  hello  ‘);//移除字串左邊的空白、右邊的空白ltrim("    hello");rtrim("hello  ");//將字串中分行符號轉換成<br />nl2br("hello\nworld!");//將特殊字元轉換為 HTML 實體htmlspecialchars("<h1>hello</h1>");htmlentities("<h1>hello</h1>");//去除字串中的HTML,第二個選擇性參數可以指定不被去除的HTMLstrip_tags("<h1>hello</h1><br><h2>world!</h2>", "<h2>");//存入資料庫之前對資料進行轉義,被轉義的字元包括單雙引號、反斜線,否則它們會被資料當作命令字元addslashes("O‘reilly");//大小寫轉換strtoupper("Zhao"); //將字串轉換為大寫 ZHAOstrtolower("Xing"); //將字串轉換成小寫 xingucfirst("zhao xing ya"); //將第一個字母轉換為大寫 Zhao xing yaucwords("zhao xing ya"); //將每個單詞第一個字母轉換為大寫 Zhao Xing Ya//填充字串為固定長度str_pad(‘Salad‘,10, ‘0‘).‘ is good.‘;/** * 操作子字串 *///用分隔字元將字串炸開成數組$array = explode(‘,‘, ‘apple,banana,watermelon‘);//將數組元素同個分隔字元聚整合字串$string = implode(‘,‘, $arr);/** * 數組 */array_chunk($array, 3);array_column($array, ‘column‘);array_pop($array); //移除並返回數組最後一個單元array_shift($array); //移除並返回數組第一個單元array_push($array,‘apple‘);array_rand($array); //從數組中隨機取出一個單元,返回單元的鍵名。is_array($var);/** * 目錄與檔案 */dirname(__FILE__); //目錄名basename(__FILE__); //檔案名稱//pathinfo()函數。若有第二個參數,函數返回的結果為字串;若無,則返回一個數組。$path =  __FILE__;$arr = pathinfo(__FILE__);$str = pathinfo($url, PATHINFO_EXTENSION); print_r($arr);//列印出Array ( [dirname] => C:\Apache24\htdocs\GuestBoard\test [basename] => testTimeStamp.php [extension] => php [filename] => testTimeStamp )//將相對路徑轉換成絕對路徑$path = ‘../index.php‘;echo realpath($path);//檔案大小filesize($filename);//磁碟空間$drive = ‘C:‘;echo ‘C盤總空間:‘.round(disk_total_space($drive)/1024/1024/1024,2).‘GB‘.‘<br>‘;echo ‘C盤剩餘空間:‘.round(disk_free_space($drive)/1024/1024/1024,2).‘GB‘;/** * 數學運算 *///四捨五入round(3.141592, 3); //3.142//向上取整ceil(3.1); //4

 

PHP常用內建函數記憶(持更)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.