Summary of PHP string functions

Source: Internet
Author: User

Strpos returns the position where string A first appears in string B (the return result is A number)

In contrast, the PHP string function is the final position of string A in string B returned by strrpos (the return result is A number)

Addcslashes adds a backslash (") to the front of a specified character, for example, echo addcslashes ($ string," Y, O "); // in the specified character" Y, O "followed by a backslash""

Addslashes adds the backslash ("") special character before a specific character in the string to single quotation marks, double quotation marks, null, and backslash ("").

Strstr obtains the substring from the first occurrence of string A in string B to the end of string B.

Strrchr obtains the substring from the last occurrence of string A in string B to the end of string B.

The array_push function is used to add the specified value to the end of the array $ array = array ("0" => "Ming", "1" => "day "); array_push ($ array, "technology ");

Print_r ($ array); the running result is array ([0] => tomorrow [1] => day [2] => technology );

The opposite PHP string function is array_unshift, which is used to add the specified value to the starting position of the array.

The array_pop function returns the last element of an array. The opposite function is the array_shift function, which returns the first element of an array.

The array_unique function is used to delete duplicate values in a specified array and return a new array.

The array_merge function is used to combine multiple numbers and return a new array.

The array_slice function is used to extract array elements of the specified length from the specified position of the array and save the extracted elements to the new array. For example, $ array = array ("I ", "Yes", "Hu", "Rain", "Xuan ");

$ Array1 = array_slice ($ array, 2, 3 );

The value of $ array1 is "Hu Yuxuan"

In contrast, the PHP string function is the array_splice function used to delete array elements from the specified position of the array and save the deleted elements to the new array.


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.