- Echo implode (",", array ('lastname', 'Email ', 'phone'); // Convert the array to a string
Explode:
- Print_r (explode (",", 'lastname, email, phone'); // convert a string to an array
Split:
- Print_r (split ("[/.-]", "2008-9.12"); // cut the string into an array with a sign of "/" or "." or "-"
Str_split:
- Print_r (str_split ("Hello Friend", 1); // cut the string
Preg_split:
- // Regular expression segmentation
- // $ Ops = preg_split ("{[+ */-]}", "3 + 5*9/2 ");
- // Print_r ($ ops); // return: Array ([0] => 3 [1] => 5 [2] => 9 [3] => 2)
Http_build_query:
- // Generate the request string after url-encoded
- $ Data = array ('localhost' => 'A ',
- 'User' => 'BB ',
- 'Password' => 'CC ');
- Echo http_build_query ($ data); // return: localhost = aa & user = bb & password = cc
Strtok:
- // Cut the string into segments
- $ String = "This is \ tan example \ nstring ";
- Echo strtok ($ string, "\ n \ t"); // return: This is
- Echo '';
- Echo strtok ("\ n \ t"); // when the second return: an example
- Echo '';
- Echo strtok ("\ n \ t"); // when the third return: string
2. many search and replace strings are r: final, I: case-insensitive
- Echo $ pos = strpos ('abcdef abcdaef ', 'A'); // The location where the first letter a appears, Case Sensitive
- Echo $ pos = strrpos ('abcdef abcdeaf', 'A'); // The last occurrence location of letter a, Case Sensitive
-
Stripos: case-insensitive strripos: case-insensitive
- Echo strstr ('User @ exa@mple.com ',' @ '); // return: @ exa@mple.com
-
Stristr: case insensitive
- Echo strchr ('User @ exa@mple.com ',' @ '); // return: @ exa@mple.com
-
Strrchr: returns @ mple.com, Preg_grep:
- // Returns the array unit that matches the pattern.
- $ Food = preg_grep ("/^ p/", array ("apple", "orange", "pip", "banana "));
- Print_r ($ food); // return: Array ([2] => pip)
Strtr:
- // Replace the string with the specified array
- $ Arr = array ("www" => "ftp", "yahoo" => "baidu ");
- Echo strtr ("www.yahoo.com", $ arr); // return value: ftp.baidu.com
- Echo strtr ("www.yahoo.com", "wo", "sx"); // return: sss. yahxx. cxm translation string replace all w with s and replace all o with x
Strspns:
- // Find the length of the first part
- Echo strspn ("abcdefg", "1234567890"); // return value: 0
- // Find the length of the initial part that is not compared
- Echo strcspn ("abcdefg", "1234567890"); // return value: 7
3. string regular match preg_match:
- // Returns the number of times that pattern matches. Either 0 (no match) or 1 time, because preg_match () will stop searching after the first match.
- If (preg_match ("/php/I", "PhP is the web scripting language of choice ."))
- Echo "exists ";
- Else
- Echo "does not exist ";
Preg_match_all:
- // On the contrary, the end of the subject will be searched all the time.
- Preg_match_all ("/\(? (\ D {3 })? \)? (? (1) [\-\ s]) \ d {3}-\ d {4}/x ",
- "Call 555-1212 or 1-800-555-1212", $ phones );
- Print_r ($ phones [0]); // Obtain all phone numbers
Ereg_replace:
- // Replace the URL with the hyperconnection
- Echo ereg_replace ("[[: alpha:] +: // [^ <> [: space:] + [[: alnum:]/]",
- "\ 0", 'this is Baidu http://www.baidu.com website. ');
- Preg_replace: filter
- $ Search = array ("' ] *?>. *? Script 'Si ", // remove javascript
- "'<[\/\!] *? [^ <>] *?> 'Si ", // remove the HTML tag
- "'([\ R \ n]) [\ s] +'", // remove the white space
- "'& (Quot | #34);' I", // replaces the HTML object
- "'& (Amp | #38);' I ",
- "'& (Lt | #60);' I ",
- "'& (Gt | #62);' I ",
- "'& (Nbsp | #160);' I ",
- "'& (Iexcl | #161);' I ",
- "'& (Cent | #162);' I ",
- "'& (Pound | #163);' I ",
- "'& (Copy | #169);' I ",
- "'& # (\ D +); 'e"); // run as PHP code
- $ Replace = array ("",
- "",
- "\ 1 ",
- "\"",
- "&",
- "<",
- "> ",
- "",
- Chr (1, 161 ),
- Chr (1, 162 ),
- Chr (1, 163 ),
- Chr (1, 169 ),
- "Chr (\ 1 )");
- Echo $ text = preg_replace ($ search, $ replace ,'TestScript alert ("adfasdf"); script ');
Preg_quote:
- // Escape the regular expression character. add \ to each character to conform to the regular expression.
- Echo preg_quote ('$40 for a g3/100','/'); // return: \ $40 for a g3 \/400
SQL _regcase:
- // Generate a regular expression for matching with no difference in size
- Echo SQL _regcase ("Foo-bar.a"); // return: [Ff] [Oo] [Oo]-[Bb] [Aa] [Rr]. [Aa]
12. Next page |