PHP string function classification, phpstring function _php Tutorial

Source: Internet
Author: User

PHP string function classification, phpstring function


1. Find the character position function:

Strpos ($str, Search,[int]): Find the first position of search in $str starting with int;

Stripos ($str, search,[int]): function returns the position of the first occurrence of a string in another string. This function is not sensitive to case

Strrpos ($str, Search,[int]): Find the last occurrence of search in $str from int

2. Extracting sub-character functions (double-byte)

Submit ($str, int start[,int length]): Extracts [length string] from strat position in $str.

Strstr ($str 1, $str 2): Searches for $str2 from $STR1 (the first position) and intercepts the end string from it, or false if none.

The Stristr () function is the same as STRSTR, but is not case sensitive.

STRRCHR () prompt returned from the last word searched; use: Fetch the file name in the path

3. Replace string

Str_replace (Search,replace, $str): Find search from $STR Replace with replace

Str_irreplace (Search,replace, $STR): Case insensitive

STRTR ($str, search,replace): Replace in this function cannot be "";

Substr_replace ($str, $rep, $start [, length]) $str The original string, $rep the replaced new string, $start the starting position, $length the length of the replacement, which is optional

4. Character length

int strlen ($STR)

5. Compare character functions

strcmp ($str 1, $str 2): $str 1>=< $str 2 are positive 1,0,-1 (string comparison)

STRCASECMP () ditto (no case)

STRNATCMP ("4", "14") compare strings by natural sort

STRNATCASECMP () ibid. (case sensitive)

6. Dividing the array function

Str_split ($str, Len): Splits the $STR by Len length returns the array

Split (search, $str [, int]): Splits the $str by the search character returns the array int is split several times, the back will not be split

Explode (search, $str [, int])

7, remove the space: LTrim, RTrim, Trim

8, add the Space function

Chunk_split ($STR, 2); Add a space to the $STR character by 2 characters;

9, CHR, Ord--Returns the specified character or ASCII

10. HTML code related functions

NL2BR (): Make \ n convert to

Strip_tags ($str [, '

']): Removes HTML and PHP tags. In $str all HTML and PHP code will be removed, and the optional parameters for HTML and PHP code will retain the code written by the optional parameters. such as: Echo Strip_tags ($text, '

');

Htmlspecialchars ($str [, Parameters]): page normal output HTML code parameter is the conversion mode

11. Character Case Conversion function

Strtolower ($STR) string converted to lowercase

Strtoupper ($STR) string converted to uppercase

Ucfirst ($STR) converts the first character of a function to uppercase

Ucwords ($STR) converts the first letter of each word to uppercase

12. Database related functions

Addslashes ($STR): Causes the single quotation mark ('), double quotation mark ("), backslash (\), and nul string in STR to be converted to \ ', \ ', \ \.

MAGIC_QUOTES_GPC = on automatically escapes the contents of the Get post cookie

GET_MAGIC_QUOTES_GPC () detects if MAGIC_QUOTES_GPC is turned on

When Magic_quotes_gpc=on, the function GET_MAGIC_QUOTES_GPC () returns 1

When Magic_quotes_gpc=off, the function get_magic_quotes_gpc () returns 0

Stripslashes () to remove backslashes from a string

http://www.bkjia.com/PHPjc/989817.html www.bkjia.com true http://www.bkjia.com/PHPjc/989817.html techarticle PHP String function classification, phpstring function 1, find character position function: Strpos ($STR, Search,[int]): Find the first position of search in $str starting with int; Stripos ($STR, Search,[int] ...

  • 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.