Follow me to learn PHP string common functions-next

Source: Internet
Author: User
1> mixed Parse_url (string $url [, int $component =-1])

Parsing URLs

    • $component, specifies the obtained part, does not write, returns an associative array that contains all the URL information specified php_url_scheme, Php_url_host, Php_url_port, Php_url_user, Php_url_pass, One of the Php_url_path, Php_url_query, or php_url_fragment to get a string of the part specified in the URL. (An integer value is returned, except when specified as Php_url_port).
$url = ' Http://username:password@hostname/path?arg=value#anchor ';p rint_r (Parse_url ($url)); Echo Parse_url ($url, PHP _url_path);//output:/path/* output: Array (    [scheme] + HTTP    [host] = hostname    [user] = Username    [ Pass] = password    [path] =/path    [query] = Arg=value    [fragment] = anchor) */

2> void Parse_str (String $str [, Array & $arr])

Resolves multiple variables from a string and can be used in conjunction with the Parse_url function

    • $arr, if you set the second variable, arr, the parsed variable will be stored in the array
$url = "http://www.web.com?act=login&id=111"; $query = Parse_url ($url, Php_url_query);p arse_str ($query); Echo $act ;//output: Loginecho $id;//output: 111

3> string Mb_substr (string $str, int $start [, int $length = NULL [, String $encoding = Mb_internal_encoding ()]])

To intercept a string by encoding

    • $start, starting Index
    • $length, the length of a unit intercepted from an index encoded
    • $econding, encoding, and file encoding methods are related
Header (' content-type:text/html; charset=utf-8; '); $STR = "Do not deceive oneself"; Echo mb_substr ($str, 0, 6, ' UTF-8 ');//output: A man can not deceive

4.> mixed Strpos (string $haystack, mixed $needle [, int $offset = 0])

Find where a string first appears

    • $haystack, find in the Hanstack string
    • $needle, find what character
    • $offset, the starting index of the lookup
    • Returned, successfully returned the corresponding index position, did not find the return false
$str = ' abcabc '; Echo strpos ($str, ' a ', 1);//output: 3

5> int strlen (string $string)

Gets the length of the string

6> string Strrev (String $string)

Returns the inverted string

7> string substr (string $string, int $start [, int $length])

Intercept string

    • Start, start index
    • $length, intercept the length, not write The Intercept to the last
      $str = ' a/b.txt '; Echo substr ($str, Strpos ($str, '/') +1); Output: B.txt

8>string strtolower (String $string)

Converts a string to lowercase and returns

String Strtoupper (String $string)

Converts a string to uppercase and returns

9> mixed Str_replace (mixed $search, mixed $replace, mixed $subject [, int & $count])

Replaces some characters in a string, which are case-sensitive. Str_ireplace function ignores case

    • $search, the character or string to be replaced
    • $replace, replace the heart character or string
    • $subject, the replaced object, that is, the total string
    • $count, the number of times the substitution occurred
$str = ' a,b,c '; Echo str_replace (', ', ', $str);//output: a b C

10> int strcmp (string $str 1, String $str 2)

Compares strings for equality and is case-sensitive. strcasecmp function ignores case

    • If STR1 is less than str2 returns < 0, if STR1 is greater than str2 returns > 0, if both are equal, 0 is returned.
  • 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.