PHP strings, array functions

Source: Internet
Author: User
Tags array length md5 hash sha1 sha1 hash

String functions

1.explode ($delimiter, $str [, $limit]) splits the $STR string $str with the $delimiter delimiter, returning a segmented array

$delimiter: Delimiter

$STR: the string to split

The number of elements that return an array after splitting when $limit>0

When $limit=0 indicates that the number of elements returned to the array after splitting is 1

When $limit<0 indicates that the array elements returned after splitting are removed $limit the number of

2.htmlspecialchars_decode ($STR) converts special HTML entities back to normal characters

3.htmlspecialchars ($STR) convert special characters to HTML entities

4.implode ($glue, $arr) converts a one-dimensional array to a string

$glue represents a connector

$arr represents a one-dimensional array

5.lcfirst ($STR) lowercase the first character of a string

$STR represents a String

6.ltrim ($str [, $k]) Delete the white space character in front of the string, the original string does not change

7.rtrim ($str [, $k]) Delete whitespace characters at the end of the string, the original string does not change

$K specifies that a white space character is deleted (starting at the leftmost (right) edge)

8.trim ($STR) Delete whitespace characters at both ends of a string

9.md5_file ($file _name) calculates the MD5 hash value of the specified file

10.MD5 ($STR) computes the MD5 hash value of a string

11.sha1_file ($file _name) calculates the SHA1 hash value of the specified file

12.SHA1 ($STR) computes the SHA1 hash value of a string

13.str_pad ($str, $len [, $str 1, $pad _type]) fills a string with the specified length

$STR: the string to populate

$len: Specifies the length of the string after the fill

$str 1: populated string

$pad _type:str_pad_right (fills the content to the right of the original string)

Str_pad_left (fills the contents to the left of the original string)

Str_pad_both (fills the contents to both ends of the original string)

If you do not specify a default Str_pad_right

14.str_repeat ($str, $multiplier) repeats the $TR string, returning the result after repetition

str_replace ($search, $replace, $subject [,& $count]) substring substitution, returning the new string after replacement

$search: substring to replace

$replace: Replaced string

$subject: original string or array

& $count: Count occurrences of replacements, returning integers

16.str_shuffle () randomly scrambles a string

17.str_split ($str [, $len]) converts a string into an array

$str: Represents the string to convert to an array

$len: Specifies the length of each array element

18.strip_tags ($str [, $allow _tags]) remove HTML and PHP tags from the string

$STR: Original string

$allow _tags: HTML and PHP tags that allow settings to be preserved

19.stripos ($str, $str 1[, $index]) find the location where $str1 first appeared in $str, and return the index

$STR: Original string

$str 1: The string to find

$index: The index position at which to start the lookup, including this position, where the index of the string starts at 0

20.strlen ($STR) returns the length of the given string

21.strpos ($str, $str 1[, $index]) returns the location of the first occurrence of $str1 in $str, case-sensitive, if not found, returns an empty

$STR: Original string

$str 1: The string to find

$index: The index position at which to start the lookup, including this location, where the index of the string is from 0

22.strrpos ($str, $str 1[, $index]) returns the location of the last occurrence of the $str1 in $str, case-sensitive, if not found, returns an empty

$STR: Original string

$str 1: The string to find

$index: The index position at which to start the lookup, including this location, where the index of the string is from 0

23.strripos ($str, $str 1[, $index]) returns the location of the last occurrence of $str1 in $str, not case-sensitive, and returns null if not found

$STR: Original string

$str 1: The string to find

$index: The index position at which to start the lookup, including this location, where the index of the string is from 0

24.strrev ($STR) Reverse string (returns a string in flashbacks)

25.strstr ($str, $str 1[, $before _needle]) finds the first occurrence of a string, returning the string after the first occurrence of the $STR1

$STR: Original string

$str 1: The string to find

$before _needle:true and False returns the string that precedes the first occurrence of $str1 when True, and returns the string after the first occurrence of $str1 when False, by default false

26.STRTR ($str, $from, $to) Replace the $from in $str with $to

27.substr_count ($str, $str 1[, $index [, $len]]) count the number of occurrences of $str1 in $str

$index indicates which index position to start the lookup

The $len represents the number of times the $len is set to the length range from $index

28.substr_replace ($str, $str 1, $index [, $len]) string substitution

$STR: Original string

$str 1: Replaced string

$index: Starting from $index index position, if no parameter $len, replace from index position to end of string

When the >0 is $len, the substitution starts at the $index position and the string in the range of $len is replaced with the $STR1

When $len <0, the substitution starts at the $index position, and the string between the original string retains the length $len is replaced by the $STR1

29.substr ($str, $index [, $len]) string intercept

$STR: Original string

$index: Where to start the Intercept

$len: Intercept length

Array functions

1.array_chunk ($arr, $size [, $preserve _keys]) tells an array to be split into multiple arrays, returning a new array without changing the original array

$arr the array to split

$size the number of elements in each array after splitting

$preserve _keys:true indicates that the original key name is preserved, false is not preserved, false is default


2.array_combine ($arr 1, $arr 2) Create an array with the value of one array as its key name, and the value of another array as its value

$arr 1 indicates the key name of the new array

$arr 2 indicates the key value of the new array

Note: The number of elements in the $arr 1 and $ARR2 must be consistent, or an error will be


3.array_count_values ($arr) counts the number of occurrences of an array element in an array, returns a new array whose key name is the key value of the original array, and the key value of the new array is the number of occurrences of the original array element


4.array_fill ($index, $length, $value) returns an array that is populated with the specified number of values

$index An integer representing the starting index of the array

$length the length of an array

$value represents the value to be populated

5.array_key_exists ($jianming, $arr) to determine if a key name exists in the array, there is a return of true, the failure returns False (if the direct output returns the result, true when output 1,false is not output)


6.array_keys ($arr, $value [, $strict]) returns some or all of the key names in the array

$arr Array

$value the key value to search for

$strict determine if the key value to search is all equal to (= = =), True and False

7.array_pad ($arr, $size, $value) fills the array to the specified length with the specified value, returns the new array, and the original array does not change

$arr represents the array to populate

$size represents the length of the array after the fill, if the value is less than or equal to the length of the $arr array, no padding

$value the value to be populated

8.array_pop ($arr) deletes the last element of the array $arr, and returns the deleted element to the function, changing the original array


9.array_shift ($arr) deletes the first element of the array $arr, and returns the deleted element to the function , changing the original array


10.array_push ($arr, $value 1[,....]) add one or more elements at the end of the $arr, returning the array length, changing the original array


11.array_rand ($arr [, $len]) randomly takes out one or more array elements, returns the key name of the element being fetched, and returns an array if more than one is fetched

$arr represents an array

$len indicates the number of array elements to be fetched

12.array_replace ($arr 1, $arr 2[, $arr 3 .....]) Replace the elements of the first array with the passed array

The Array_replace () function replaces the value of the $arr 1 array with the value of the same key as the following array element. If a key exists in the first array and also exists in the second array, its value is replaced by the value in the second array. If a key exists in the second array, but does not exist in the first array, the element is created in the first array. If a key exists only in the first array, it will remain unchanged. If multiple alternate arrays are passed, they are processed sequentially, followed by an array that overrides the previous value.

13.array_search ($value, $arr [, $strict]) searches for $value in array $arr, returns its key name successfully, and fails to return false

$value the value to search for

$arr Array

$strict if the optional third parameter strict is TRUE, Array_search () examines the exact same element in $arr. That means checking the type of $value in $arr, too.


14.array_slice ($arr, $index [, $len [, $preserve _keys]) takes a fragment from the $arr array to form a new array, without changing the original array

$arr the original array

The $index represents the beginning of the position from the array subscript $index and, if negative, the last representation of the array element-1

$len indicates the length taken out

$preserve _keys is true, retains the key name of the extracted element in the original array, false does not persist, default is False


15.array_splice ($arr, $index [, $len [, $replace]]) removes a fragment from the $arr array, the deleted array element is re-formed into a new array, and the original array is changed

$arr the original array

The $index represents the deletion from the position where the array is labeled $index, and if negative, the last representation of the array element-1

$len indicates the length of the deleted element

$replace the deleted place is replaced with a value of $replace (can be an array, or it can be a string)

16.array_unique ($arr) removes duplicate values from the array, returns a new one, does not change the original array

17.array_unshift ($arr, $value 1[,....]) add one or more elements at the beginning of the $arr, returning the array length, changing the original array


18.count ($arr) Length of statistical array $arr


19.in_array ($value, $arr [, $strick]) determines whether $value is the element in $arr, is the return true, not the return false

$strick true to check the data type, false when the data type is not checked, false by default


This article is from the "Snow No Trace" blog, please make sure to keep this source http://yjyan.blog.51cto.com/9291126/1792246

PHP strings, array 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.