PHP function Accumulation

Source: Internet
Author: User
Tags sprintf strtok
String

Ltrim ()

Removes spaces from the start (left) of the string.

Rtrim ()

Removes spaces from the end (right) of the string.

Trim ()

Removes spaces before and after the entire string.

Nl2br ()

Use the string as the input parameter and use the <br/> mark in XHTML to replace the line break in the string. Note: HTML ignores pure spaces, so if you do not use the nl2br () function to filter this output result, it looks like a separate line (unless the browser window forces a line break ).

Sprintf ()

String sprintf (string format [, mixed ARGs...])

Use format code instead of variables to describe the basic shape of the output string. Other parameters are used to replace the variable of the format string.

Printf ()

Void printf (string format [, mixed ARGs...])

Use format code instead of variables to describe the basic shape of the output string. Other parameters are used to replace the variable of the format string.

Strtoupper ()

Converts a string to uppercase, for example, strtoupper ($ subject)

Strtolower ()

Converts a string to lowercase, for example, strtolower ($ subject)

Ucfirst ()

If the first character of a string is a letter, it is converted to uppercase, for example: ucfirst ($ subject)

Ucwords ()

Converts the first letter of each word in a string to uppercase, for example, ucwords ($ subject)

Addslashes ()

A string is required as the input parameter. After function processing, a reformatted string is returned. Conversion refers to escaping the input characters and adding a backslash before the double quotation marks. This function is controlled by magic_quotes_gpc configuration commands.

Stripslashes ()

Use the get_magic_quotes_gpc () function to check that commands on the system are enabled. If variables from these methods are automatically referenced in quotation marks, the function returns true. If this command is enabled on the system, you must call the stripslashes () function before displaying user data. Otherwise, the backslash is displayed.

Explode ()

Array explode (string separator, string input [, int limit]);

This function carries an input string as a parameter, and splits the string into small parts based on a specified delimiter, and returns the small parts to an array. You can use the optional parameter limit to limit the number of small pieces of strings.

Implode ()

Use this function to achieve the opposite effect of the function explode.

Join ()

Use this function to achieve the opposite effect of the function explode.

Strtok ()

String strtok (string input, string separator );

Unlike the function explode (), each time a string is divided into several small pieces, the strtok () function extracts only one segment (called a token) from the string at a time ). For processing a word extracted from a string at a time, this function works better.

Substr ()

String substr (string, int start [, int length]);

This function allows us to access a substring with a given start point and end point of a string. This function is useful when we need to obtain a part of a fixed format string. This function returns a copy of The substring of the string.

Strcmp ()

Int strcmp (string str1, string str2 );

This function requires two parameter strings for comparison. If the two strings are equal, the function returns 0. If the dictionary order str1 is behind str2, a positive number is returned. If the dictionary order is different, a negative number is returned. This function is case sensitive.

Strcasecmp ()

This function is the same as strcmp () except case insensitive.

Strnatcmp ()

This function is sorted by nature.

Strlen ()

If a string is passed to it, the function returns the length of the string.

Strstr ()

String strstr (string haystack, string needle );

Pass a substring parameter to be searched and a target keyword string parameter to the function. If it is found, the string to be searched is returned. Otherwise, the return value is false. If more than one target keyword exists, the returned string starts from the position where the first target keyword appears.

Strchr ()

It is exactly the same as the strstr () function.

Strrchr ()

It is almost the same as the strstr () function, but the searched string is returned from the beginning of the final position where the target keyword appears.

Stristr ()

The difference between strstr () and strstr () is case-insensitive.

Strpos ()

Int strpos (string haystack, string needle, int [offset]);

The returned integer represents the first occurrence of the target keyword substring in the searched string. Generally, the first character is 0.

Strrpos ()

This function is almost the same as the strpos () function, but returns the position of the last occurrence of the target keyword substring in the searched string.

Str_replace ()

Mixed str_replace (mixed needle, mixed new_needle, mixed haystack [, Int & COUNT]);

This function replaces "Needle" in all haystack with "new_needle" and returns the result after replacement of haystack. The fourth optional parameter contains the number of replacement operations to be performed.

Substr_replace ()

String substr_replace (string, string replacement, int start, int [length]);

This function uses the string replacement to replace a part of the string. The specific part depends on the starting position value and the value of the optional parameter length.

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.