PHP----String

Source: Internet
Author: User
Tags parse string
Var_dump (Explode (":","Php:123"));//Return array by: Split. Output: PHP, 123EchoImplode (',',Array(' A ',' B '));//Return string output: a bList($user,$pass) = Explode (":","Php:123");Echo$user,$pass;//Return string output: php123$array=Array(' php ',' 123 ');EchoJoin",",$array);//Return string output: php,123STRRCHR (' Abab ',' A ');//ab (last seen)Substr' ABCD ',1);//BCD (returns a substring of a string)Substr' ABCD ',2,2);//CDSubstr' ABCD ',-1,1);//d (Position confirmation is truncated by length)Substr' ABCD ',-2,2);//CDStrpos (' abcd@yahoo.com ','@');//4 (positional characters)Substr' abcd@yahoo.com ',0, Strpos (' abcd@yahoo.com ','@'));//ABCDStr_repeat (' A ',5);//aaaaa (Repeats a string)Str_shuffle (' ABCD ');//CBDA Note: Changes with refresh (randomly scrambling a string)Stripos (' ABCA ',' A ');//0 (Note: A on the first seat, find the position where the string first appears ( case-insensitive))Strripos (' ABCA ',' A ');//3 (calculates the location of the last occurrence of the specified string in the target string ( case-insensitive))Strrpos (' ABCA ',' A ');//0 (calculates the location of the last occurrence of the specified string in the target string)Substr_count (' ABCD ',' B ');//1 (counts the number of occurrences of a string)STRCSPN (' Aabb cc ',' C ');//5 (returns the number of characters to find in a string before any specified character is found)STRSPN (' abcdef ',' abc ');//3 (returns the number of specific characters contained in the string)STRSPN (' abcdef ',' BC ');//0STRSPN (' abcdef ',' BC ',1,5);//2Chr $);//a (get ASCII encoding)Ord' A ');//65STRCHR (' Aa BB ',' A ');//a BB (search for a string to return the specified character)STRCHR (' Aa BB ', About);//For empty note: ASCII c:99STRCHR (' Aa BB ', the);//a BB Note: ASCII a:97Addcslashes (' Aabb ',' A ');//\a\abb (function to add a backslash before the specified character)Addslashes ("AA bb ");//aa bb\ ' (Escape: Predefined ', \)Lcfirst (' Hello World ');//hello World (first character lowercase)LTrim":p hp:123:",':');//php:123 (remove left and right characters)RTrim":p hp:123:",':');//:p hp:123 (remove right character)Trim":p hp:123:",':');//php:123 (remove left character)NL2BR ("Php\r\n123");//php
123 (Insert Career tab)WordWrap (' aaabbb ',3,'
',true);//AAA
BBB (break string to a specified number of strings)Quotemeta (' ABCD. ()');//abcd\.\ (\)---(Reference meta-character:. + *?) [ ^ ] ( $ ) )Similar_text (' ABCD ',' AAAA ',$sim);//25 (calculates the similarity of two strings)Similar_text (' ABCD ',' AAAA ');//1sprintf' name:%s,age:%d ',' AAA ', A);//(return formatted string)Str_ireplace (' AA ',' One ',' AA22 ');//1122 (ignoring case versions)STRCASECMP (' Hello ',' Hello ');//0 Note: left>right: Positive, Reverse: negative (binary security comparison string (case insensitive))Str_pad (' AAA ',Ten);//aaa (followed by 7 spaces)--(fills a string with another string for a specified length)Str_pad (' AAA ',Ten,'-', Str_pad_left);//-------AAA;Str_pad (' AAA ',Ten,'-', Str_pad_both);//---AAA----$str="Hello

1

"; Strip_tags ($str);//hello1 (remove HTML and PHP tags from the string)Strip_tags ($str,'

'); //hello

1

Stripcslashes (' AA\\BB ');//aab (escaped string minus backslash)Stripcslashes (' AA\\\BB ');//AA\BBStripslashes (' This is one ');//This is one (dereference a reference string)STRISTR (' ABc@163.com ',' B ');//bc@163.com (Ignore case version of function)STRISTR (' ABc@163.com ',' B ',true);//aStrstr' ABc@163.com ','@');//@163.com (Find first occurrence of string)Strstr' ABc@163.com ','@',true);//ABCStrlen' AB CD ');//5 (Get string length)strcmp"AAA","BBB");//-1 Note: Binary secure string comparisonstrncmp' ABCD ',' AB ',2);//0 Note: 2 matches 0, Part 1, no -1strncmp' ABCD ',' A ',2);//1strncmp' ABCD ',' C ',2);//-1Substr_compare (' ABCD ',' B ',1,1);//0 (binary security comparison string (specified length from offset))Substr_compare (' ABCD ',' C ',-2,1);//0Substr_compare (' ABCD ',' B ',1,1,true);//0Substr_replace (' abcd E ',' 1 ',5);//ABCD 1 (substring of replacement string)Substr_replace (' abcd E ',' 1 ', -1);//ABCD 1Substr_replace (' abcd E ',' 1 ',2,2);//ab1 eStr_replace (' AA ', One,' Aa22 ');//1122 (sub-string substitution)STRPBRK (' AbAc ',' A ');//ac (finds any one character of a set of characters in a string)STRPBRK (' AbAc ',' CB ');//bac (finds any one character of a set of characters in a string)Strrev (' ABCD ');//DCBA (Inverted string)Strtok' Aa/bb ','/');//AA (Tag split string)Strtolower (' ABc ');//abc (converts a string to lowercase)Strtoupper (' ABc ');//abc (converts a string to uppercase)Ucfirst (' ABCD ');//ABCD (converts the first letter of a string to uppercase)Ucwords (' ABCD cc ');//ABCD Cc (converts the first letter of each word in a string to uppercase)TRTR (' AABBCC ',' AC ',' One ');//11bb11 (remove whitespace characters from the beginning and end of the string)$arr=Array(' Hello '=' Hi ',' World '=' Today ');EchoSTRTR (' Hello World ',$arr);//hi TodayTrim' ABCD ');//abcd (remove whitespace characters from the beginning and end of the string)Trim' XABCDX ',' x ');//ABCDMd5_file ("C:\d\d.txt");//d.txt file to existMD5 ("C:\d\d.txt");//Dual MD5 encryption classTestMd5{ functionget($num){$num=MD5 (MD5 ($num)."En");return$num; }}$testMd 5=NewTestMd5 ();Echo$testMd 5->get ("Test");$date= Date ("y-m-d h:i:s");List($y,$m,$d,$h,$i,$s) = Split ('[- :]',$date);Echo"$y year $m month $d day $h $i minutes $s seconds";//Explode stringNumber_format (1234.56);//1,2345 (formatted number)Number_format (1234.56,2,',','');//1234,56Number_format (1234.56,2,'.',' ');//1 234.56$str=' FIRST=ONE&ARR[]=A+B&ARR[]=CCC ';p Arse_str ($str);//Parse string variable$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$arr 1=Array(' Img1.png ',' Img10.png ',' Img2.png '); Sort ($arr 1);//Press key valueNatsort ($arr 1);//By Val value$line=' AA ' bb cc. ' Dd.txt ';$parsed= Str_getcsv ($line,' ','"');//Parse CSV string as an arrayVar_dump ($parsed);//array (3) {[0]=> string (2) "AA" [1]=> string (6) "BB cc." [2]=> string (6) "Dd.txt"}Print_r (Str_split (' Hello World '));//Convert string to arrayPrint_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 [Ten] + 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); }); });

    The above describes the PHP----String, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.