PHP----String

來源:互聯網
上載者:User
var_dump(explode(":","php:123"));    //返回array  按: 分割。 輸出:php, 123echo implode(',', array('a','b'));   //返回string 輸出:a blist($user,$pass) = explode(":","php:123");echo$user,$pass;      //返回string 輸出:php123$array = array('php','123');echo join(",",$array); //返回string 輸出: php,123strrchr('abab', 'a');           //ab(最後一次出現)substr('abcd',1);               //bcd(返回字串的子串)substr('abcd',2,2);             //cdsubstr('abcd',-1,1);            //d(把位確認按長度截取)substr('abcd',-2,2);            //cdstrpos('abcd@yahoo.com', '@');  //4(定位字元)substr('abcd@yahoo.com', 0,strpos('abcd@yahoo.com','@')); //abcdstr_repeat('a',5);              //aaaaa(重複一個字串)str_shuffle('abcd');            //cbda    註:隨重新整理變化(隨機打亂一個字串)stripos('Abca','a');            //0 (註:a在第一個位子上,尋找字串首次出現的位置(不區分大小寫))strripos('AbcA','a');           //3 (計算指定字串在目標字串中最後一次出現的位置(不區分大小寫))strrpos('abcA','a');            //0(計算指定字串在目標字串中最後一次出現的位置)substr_count('abcd','b');       //1(計算字串出現的次數)strcspn('aabb cc','c');          //5(返回在找到任何指定的字元之前,在字串尋找的字元數)strspn('abcdef','abc');          //3(返回在字串中包含的特定字元的數目)strspn('abcdef','bc');           //0strspn('abcdef','bc',1,5);       //2chr(65);                        //A (擷取ASCII編碼)ord('A');                       //65strchr('Aa bb','a');            //a bb(搜尋一個字串返回指定的字元)strchr('Aa bb',99);             //為空白       註:ASCII  c:99strchr('Aa bb',97);             //a bb       註:ASCII  a:97  addcslashes('aabb','a');        //\a\abb(函數在指定的字元前添加反斜線)addslashes("aa bb'");           //aa bb\'(轉義:預定義',\)lcfirst('Hello World');           //hello World(第一個字元小寫)ltrim(":php:123:",':');           //php:123(去掉左右字元)rtrim(":php:123:",':');           //:php:123(去掉右字元)trim(":php:123:",':');            //php:123(去掉左字元)nl2br("php\r\n123");                        //php
123(插入轉列標籤)
wordwrap('aaabbb',3,'
'
, true); //aaa
bbb(打斷字串為指定數量的字串)
quotemeta('abcd.()'); //abcd\.\(\)---(引用元字元:. + * ? [ ^ ] ( $ ) )similar_text('abcd','aaaa',$sim); //25(計算兩個字串的相似性)similar_text('abcd','aaaa'); //1sprintf('name:%s,age:%d','aaa',12); //(返回格式化字串)str_ireplace('aa','11','AA22'); //1122(忽略大小寫版本)strcasecmp('Hello','hello'); //0 註:left>right:正,反之:負(二進位安全比較字串(不區分大小寫)) str_pad('aaa',10); //aaa (後跟7個空格)--(使用另一個字串填充字串為指定長度)str_pad('aaa',10,'-',STR_PAD_LEFT); //-------aaa;str_pad('aaa',10,'-',STR_PAD_BOTH); //---aaa----$str = "hello

1

"
;strip_tags($str); //hello1 (從字串中去除 HTML 和 PHP 標記)strip_tags($str,'

'); //hello

1

stripcslashes('aa\\bb'); //aab(轉義的字串 去掉反斜線)stripcslashes('aa\\\bb'); //aa\bbstripslashes('This is \0 one'); // This is one(反引用一個引用字串) stristr('ABc@163.com','b'); //Bc@163.com(函數的忽略大小寫版本)stristr('ABc@163.com','b',true); //Astrstr('ABc@163.com','@'); //@163.com(尋找字串的首次出現)strstr('ABc@163.com','@',true); //ABcstrlen('ab cd'); //5(擷取字串長度)strcmp("aaa", "bbb"); //-1 註: 二進位安全字串比較strncmp('abcd','ab',2); //0 註:2個匹配0,部分1,無-1strncmp('abcd','a',2); //1strncmp('abcd','c',2); //-1substr_compare('abcd','b',1,1); //0(二進位安全比較字串(從位移位置比較指定長度))substr_compare('abcd','c',-2,1); //0substr_compare('abcd','B',1,1,true); //0substr_replace('abcd e','1', 5); //abcd 1(替換字串的子串)substr_replace('abcd e','1', -1); //abcd 1substr_replace('abcd e','1', 2,2); //ab1 estr_replace('aa',11,'aa22'); //1122(子字串替換)strpbrk('abAc','A'); //Ac(在字串中尋找一組字元的任何一個字元)strpbrk('abAc','cb'); //bAc(在字串中尋找一組字元的任何一個字元)strrev('abcd'); //dcba(反轉後的字串)strtok('aa/bb','/'); //aa(標記分割字串)strtolower('ABc'); //abc(將字串轉化為小寫)strtoupper('ABc'); //ABC(將字串轉化為大寫)ucfirst('abcd'); //Abcd(將字串的首字母轉換為大寫)ucwords('abcd cc'); //Abcd Cc(將字串中每個單詞的首字母轉換為大寫)trtr('aabbcc','ac','11'); //11bb11(去除字串首尾處的空白字元)$arr = array('hello' => 'hi', 'world' => 'today');echo strtr('hello world',$arr); //hi todaytrim(' abcd '); //abcd(去除字串首尾處的空白字元)trim('xabcdx','x'); //abcdmd5_file("C:\d\d.txt"); //d.txt 檔案要存在md5("C:\d\d.txt");//雙重md5加密classTestMd5{functionget($num){$num=md5(md5($num)."En"); return$num; }}$testMd5 = new TestMd5();echo$testMd5->get("test");$date = date("Y-m-d H:i:s");list($y,$m,$d,$h,$i,$s) = split('[- :]', $date); echo"$y 年$m 月 $d 日 $h 時 $i 分$s 秒"; //分解字串number_format(1234.56); //1,2345(格式化數字)number_format(1234.56,2,',',''); //1234,56number_format(1234.56,2,'.',' '); //1 234.56$str = 'first=one&arr[]=a+b&arr[]=ccc';parse_str($str); //解析字串變數$first; //one$arr[0]; //a b$arr[1]; //ccc;parse_str($str,$put);$put['first']; //one$put['arr'][0]; //a b$put['arr'][1]; //ccc$arr1 = array('img1.png','img10.png','img2.png');sort($arr1); //按key值natsort($arr1); //按val值$line = 'aa "bb cc." dd.txt'; $parsed = str_getcsv( $line,' ','"'); //解析 CSV 字串為一個數組var_dump( $parsed );//array(3) { [0]=> string(2) "aa" [1]=> string(6) "bb cc." [2]=> string(6) "dd.txt" }print_r(str_split('hello world')); //將字串轉換為數組print_r(str_split('hello world',3));/*Array( [0] => h [1] => e [2] => l [3] => l [4] => o [5] => [6] => w [7] => o [8] => r [9] => l [10] => d)Array( [0] => hel [1] => lo [2] => wor [3] => ld)*/

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介紹了PHP----String,包括了方面的內容,希望對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.