PHP Common String functions

Source: Internet
Author: User
Tags uppercase letter

String Handling Functions
  1. End-to-end processing

    • trim ( string $str [, string $character_mask = " \t\n\r\0\x0B" ] )

      This function returns str the result after the string is stripped of the trailing white space character. If you do not specify a second parameter,trim () will remove these characters:

    • ltrim()and rtrim() the left and right of the string, respectively

  2. Casing Processing

    • ucfirst(string $str)

      str Converts the first character (if the first character is a letter) to an uppercase letter, and returns the string.

    • lcfirst(string $str)

      str Converts the first character (if the first character is a letter) to a lowercase letter and returns the string.

    • ucwords ( string $str [, string $delimiters = " \t\r\n\f\v" ] )

      str Converts the first character in each word (if the first character is a letter) to an uppercase letter, and returns the string.

      The definition of the word here is a delimiters substring immediately following the parameter (default: Space character, tab, newline, carriage return, horizontal line, and vertical line).

    • strtolower ( string $string )

      string Converts all alphabetic characters to lowercase and returns.

    • strtoupper ( string $string )

      string Converts all alphabetic characters to uppercase and returns.

  3. String-Array Conversion

    • explode ( string $delimiter , string $string [, int $limit ] )

      This function returns an array of strings, each of which is string a substring separated by a string delimiter as a boundary point.

    • implode ( string $glue , array $pieces )

      Converts the value of a one-dimensional array to a string, aliasjoin

    • str_split ( string $string [, int $split_length = 1 ] )

      Converts a string to an array.

    • chunk_split ( string $body [, int $chunklen = 76 [, string $end = "\r\n" ]] )

      It is useful to use this function to split a string into small chunks. For example, convert the output of Base64_encode () to a string that conforms to RFC 2045 semantics. It is chunklen inserted behind each character end . example

  4. Find replacements

    • strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

      Returns the needle haystack number position that first appears in the. Not found back false

    • str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

      The function returns a string or an array. The string or array is the subject result of replacing all of search them replace . $count Returns the number of matches. $search and $replace can be arrays for multiple substitutions.

    • strtr ( string $str , string $from , string $to ) $to will replace the $from problem easily

      Strtr (string $str, array $replace _pairs) //similar str_replace

      This function returns a copy of str and will be in from The characters specified in the are converted to the corresponding characters in the to . For example, N] each occurrence will be replaced with < Span class= "Inline-math-svg math-jax-postprocess" > N] , where $n is a displacement (offset) that is valid for all two parameters.

      If from to It is not equal to the length, the extra character portion is ignored. Will be the str same length as the returned value.

    • strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )

      Returns the string from the beginning of the haystack needle first occurrence to the haystack end of the string. aliases strchr

    • strrchr ( string $haystack , mixed $needle )

      The function returns a portion of the haystack string, starting at needle the last occurrence, until the haystack end.

    • str_repeat ( string $input , int $multiplier )

      Returns input multiplier The result after repeating the second.

    • str_pad ( string $input , int $pad_length [, string $pad_string = " " [, int $pad_type = STR_PAD_RIGHT ]] )

      The function returns the input result of being padded from the left, right, or both ends to the length of the set. If an optional pad_string parameter is not specified, input It will be filled with a space character, otherwise it will be pad_string filled to the specified length.

    • str_shuffle ( string $str )

      Disrupts a string, using any one of the possible sorting schemes.

    • strrev ( string $string )

      Returns string the inverted string.

    • substr ( string $string , int $start [, int $length ] )

      Returns string a string start length that is specified by the and parameter substring. detail

    • substr_replace ( mixed $string , mixed $replacement , mixed $start [, mixed $length ] )

      Substitution is made in a copy of the string by using a substring that is qualified with the string start optional length parameter replacement .

PHP Common String functions

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.