PHP Common function string Operation review

Source: Internet
Author: User

A review of 1.php string functions

PHP Lookup function to locate the location where the string you are looking for appears

Strpos (string position) string Locator function

Strpos ($strA, $strB) is used to query the position of the string $strb in the string $str, which is strictly case-sensitive. Stripos () is the same as the above function, when one of the distinctions is that this method is case-insensitive;

Strrpos () uses the same method as the above function, but this function is used to find the last position $strb appears in $stra.

Intercept functions for strings

SUBSTR ($strA, 3,5) The function means to intercept the string $stra from the third character, and the length of the intercept is 5.

Strstr ($strA, $strB) intercepts the string $stra from the position where $STRB occurred, intercepts the tail of the string, and returns the truncated string.

STRISTR () uses the same method as above, but the Intercept function is case-insensitive.

Strrchar from the last position that appears, this function is often used to get the folder where the file is located.

Replace function

Str_replace ("A", "B", $strA) returns the replaced string, the function is to replace the $stra in the first, a to B; the length of a and B can be different

STRTR ($strA, ' A ', ' B ') returns the replaced string, where the length of a and B must be the same strictly first.

Substr_replace ($strA, $strB, $star [, length]) replaces the string $stra from the start position, the length of the replacement, and finally returns the replacement string to $STRB;

Comparison functions for strings

strcmp ($a, $b) $a > = < $b, respectively, the 1,0,-1 is returned;

function to remove two spaces from a string

Trim () The function is to remove spaces on either side of the string

Functions that insert spaces

Chunk_split ($a, 1, "/") the function is to insert the string $ A every other character, and the "/" is inserted;

Functions for database character segment operations

Addslashes () converts spaces and quotes in accepted strings into special symbols

PHP Common function string Operation review

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.