PHP 學習筆記 - - - 簡單方法的使用 (字符串與數字)

1.經常使用方法php

            ini_set('display_errors',1);   // 若是出現錯誤,將錯誤信息在頁面顯示出來html

            error_reporting(E_ALL | E_STRICT);// 顯示全部的錯誤信息post

            // 去除字符串中的換行符加密

            $posting = nl2br($_POST['posting']);url

            // 將特定html標籤轉換爲實體版本spa

            $posting = htmlspecialchars($_POST['posting'],特定的html標籤);操作系統

            // 將全部html標籤轉換爲實體版本code

            $posting = htmlentities($_POST['posting']);orm

            

            // 移除全部的html和php標籤htm

            $posting = strip_tags($_POST['posting']);

            // 將任意值傳送到php腳本(將值徹底轉換爲適合做爲url的一部分傳輸)

            urlencode();


            注意:

            PHP中字符串的鏈接用 " . " 

            PHP中若是用雙引號來鏈接變量,只會將其視爲一個字符串,鏈接變量用單引號

            如:$name1 = "test";

                $name2 = "value";

                $name = "$name1 $name2";

                $nameValue = '$name1 $name2';

            其中$name的值爲$name1 $name2而$nameValue的值爲test value.

         


           // 數據加密(沒有解密方法)

            crypt(加密數據);


            // 數據加密(有解密方法)

            mcrypt_encrypt(加密數據);


            // 對應解密方法

            mcrypt_decrypt(須要解密的數據);


            注意:

            若是須要使用mcrypt的加密,解密方法,須要安裝Mcrypt擴展



            // 切割字符串(從數據開始,到目標位置結束)

            $first = strtok(須要切割的數據 , 以什麼要求切割);

            $first = substr(須要切割的數據 , 開始切割的位置 , 結束切割的位置);

            // 字符串長度(包含空格,符號)

            $length = strlen(字符串);

            // 字符串長度(獲取字符串中的單詞數量)

            str_word_count();

            


            // 字符串比較(將用返回整數的形式返回兩個字符串的比較結果)

            strcmp();

            // 與上述方法相似

            strnatcmp();

            //不區分大小寫

            strcasecmp();

            strnatcasecmp();

            // 獲取字符串中從被查找字符串到末尾的值

            $test = "abcdefghijklmnopqrstyuvwxyz";


            // value 的值爲 jklmnopqrstyuvwxyz

            $value = strstr($test,'j');

            // 同上,區別在於不區分大小寫

            stristr();

            

            // 獲取須要查找的字符在被查找字符中第一次出現的位置

            strpos($test,'j')

            // 同上,區別在於不區分大小寫

            stripos();

            


        // 格式化數字

        round(4.30); // 4

        round(4.25674,2);//4.26

        number_format(428.4959,2)// 428.50

        number_format(428,2)// 428.00

        number_format(123456789) // 123,456,789

        // 建立隨機數

        $n = rand();

        $n = rand(0,10);

        // 建立範圍內最大的隨機值, 返回值將根據操做系統的改變爲改變

        $n = getrandmax();

        // 絕對值

        $n = abs(10);

相關文章
相關標籤/搜索