Php string functions

Source: Internet
Author: User
Tags chr ord php code split strcmp strlen trim knowledge base

Addslashes: Adds a slash to the string.
Bin2hex: binary to hexadecimal.
Chop: removes consecutive gaps.
Chr: returns the character of the ordinal value.
Chunk_split: splits a string into segments.
Convert_cyr_string: convert the ancient Slavic string to another string.
Crypt: encrypt the string with des encoding.
Echo: output string.
Explode: cut string.
Flush: clears the output buffer.
Get_meta_tags: extracts all metadata marked by meta from the file.
Htmlspecialchars: Convert Special characters into html format.
Htmlentities: converts all characters into html strings.
Implode: converts an array into a string.
Join: converts an array into a string.
Ltrim: removes consecutive white spaces.
Md5: calculate the md5 of the string.
Nl2br: converts a line break to <br>.
Ord: returns the ordinal value of a character.
Parse_str: parses the query string into a variable.
Print: output string.
Printf: output the formatted string.
Quoted_printable_decode: convert an qp encoded string to an 8-bit string.
Quotemeta: add a reference symbol.
Rawurldecode: restores a string from a url-specific format to a normal string.
Rawurlencode: encode a string into a url-specific format.
Setlocale: configure the region information.
Similar_text: string similarity calculation.
Soundex: calculates the pronunciation of a string.
Sprintf: format the string.
Strchr: find the first occurrence character.
Strcmp: string comparison.
Strcspns: the length of different strings.
Strip_tags: remove the html and php tutorials.
Strips tutorial lashes: remove the backslash character.
Strlen: Gets the string length.
Strrpos: find the last occurrence of a character in the string.
Strpos: searches for the first occurrence of a character in a string.
Strrchr: Gets the string starting from the last occurrence of a character.
Strrev: Reverse string.
Strspns: identifies the number of masks that a string falls into another string.
Strstr: returns the string from the beginning to the end of a string.
Strtok: cut string.
Strtolower: converts all strings to lowercase letters.
Strtoupper: converts all strings to uppercase.
Str_replace: string replacement.
Strtr: converts certain characters.
Substr: obtains some strings.
Trim: removes spaces at the beginning and end of a string.
Ucfirst: uppercase for the first character of the string.
Ucwords: change the first letter of each character in the string to uppercase.


String functions in php are also easy to understand. Today, we have summarized nearly 12 php string functions for you, hoping to help other users and increase their php knowledge base.
1. Character location search function:
Int strpos (string $ str, mixed search, [int]): searches for the location where search first appeared in $ str (starting from int, ignoring any value before int );
Int stripos (string $ str, string search, [int]): returns the position where the string first appears in another string. This function is case insensitive.
Strrpos ($ str, search, [int]): searches for the last occurrence position of search in $ str from int (starting from int, ignoring any value before int );

2. Extract sub-character functions (dual-byte)
Submit ($ str, int start [, int length]): Extracts [length strings] starting from the strat position in $ str.
Strstr ($ str1, $ str2): Searches for $ str2 from $ str1 (the first position) and truncates the string from the start to the end. If not, false is returned.
Stristr () is the same as strstr, but is case insensitive.
Strrchr () is returned from the last searched character. Usage: get the file name in the path
3. php string functions that replace strings
Str_replace (search, replace, $ str): search for search from $ str and replace it with replace.
Str_irreplace (search, replace, $ str ):
Strtr ($ str, search, replace): In this function, replace cannot be "";
Substr_replace ($ str, $ rep, $ start [, length]) $ str original string, $ new after rep replacement
String, starting position of $ start, and length of $ length. Optional.
4. Character length
Int strlen ($ str)
5. Comparison of character functions
Int strcmp ($ str1, $ str2): $ str1 >=< $ str2 is positive 1, 0,-1 (string comparison)
Strcasecmp () Same as above (case-insensitive)
Strnatcmp ("4", "14") compares strings in natural order
Strnatcasecmp () is the same as above (case sensitive)
6. php string functions split into arrays
Str_split ($ str, len): Splits $ str by len length and returns an array.
Split (search, $ str [, int]): Splits $ str by the search character and returns the number of times the array int is split.
Expload (search, $ str [, int])
7. Remove spaces:
Ltrim, rtrim, trim
8. Space function
Chunk_split ($ str, 2); add a space to the $ str string containing 2 characters;
9. chr and ord -- return the specified character or ascii
10. Functions related to html code
Nl2br (): converts n to <br>.
Strip_tags ($ str [, '<p>']): removes html and php tags.
In $ str, all html and php code will be removed. The optional parameters are html and php code.
Code written by optional parameters.
For example, echo strip_tags ($ text, '<br> <p> ');

Htmlspecialchars ($ str [, parameter]): The html code parameters output normally on the page are converted.
11. php string functions for case-insensitive character conversion
Strtolower ($ str) string to lowercase
Strtoupper ($ str) string to uppercase
Ucfirst ($ str) converts the first character of the function to uppercase.
Ucwords ($ str) converts the first letter of each word to uppercase
12. php string functions related to database tutorials
Addslashes ($ str): Enables single quotation marks ('), double quotation marks ("), backslash (), and nul in str.
String ',",\.
Magic_quotes_gpc = on automatically escapes the get post cookie content
Get_magic_quotes_gpc () check whether magic_quotes_gpc is enabled
Stripslashes () removes the backslash from the string

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.