Summary of String functions

Source: Internet
Author: User
Tags crc32 crypt format definition md5 hash rtrim

A detailed description of string functions

Addcslashes-adds a backslash escape character for some characters inside a string


String Addcslashes (String $str, string $charlist);

Returns a string that has a backslash in front of the character in the parameter charlist list.

addslashes-characters inside a string are escaped in the specified manner


String addslashes (STRING$STR);

Returns a string that, for the purposes of the database query statement, is preceded by a backslash in front of some characters.

bin2hex-converts binary data to hexadecimal notation


String Bin2Hex (STRING$STR);

Returns an ASCII string that is the hexadecimal representation of the parameter str.

alias function for Chop-rtrim ()

chr-returns the ASCII code of a character


String chr (int $ascII);

Returns the character specified by the corresponding ASCII.

Chunk_split-divide a string into small pieces at a certain length of character


String Chunk_split (String $str [, int$length=7[,string $end = "\ r \ n"]);

Use this function to split a string into small chunks.

Convert_cyr_string-converting Slavic characters to other characters


String convert_cyr_string (String $str, String $from, string $to);

This function converts the given string from one Cyrillic character to another, returning the converted string.

convert_uudecode-decrypting a string


String Convert_uudecode (String $data)

Convert_uudecode () decodes a uuencode encoded string.

convert_uuencode-Encrypt a string


String Convert_uuencode (String $data)

Convert_uuencode () encodes a string using the uuencode algorithm.

The uuencode algorithm converts all (including binary) strings into characters that can be output and can be safely applied to network transmissions. Data encoded using Uuencode will be about 35% larger than the source data.

count_chars-returns the character usage information for a string


Mixed Count_chars (string $string [, int $mode = 0])

Counts each byte value in a string (0: 255) The number of occurrences, using multiple modes to return results.

crc32-computes a crc32 polynomial of a string


int Crc32 (String $str)

Generates a 32-bit cyclic redundancy check code polynomial for str . This is typically used to check the integrity of the data being transmitted.

crypt-one-way hash encryption function


String crypt (String $str [, String $salt])

Crypt () returns a hash string based on the standard UNIX DES algorithm or other available alternative algorithms on the system.

Echo-used to display some content


void Echo (String $arg 1 [, String $ ...])

Output all parameters.

Echo is not a function (it's a language structure), so you don't have to use parentheses to indicate arguments, single quotes, double quotes. Echo (unlike other language constructs) does not behave like a function, so it is not always possible to use the context of a function. Also, if you want to pass multiple arguments to echo, you cannot use parentheses.

Explode-converts a string into an array form with a separator


Array explode (string $delimiter, string $string [, int $limit])

This function returns an array of strings, each of which is a substring of string, separated by the delimiter of the strings as the boundary points.

fprintf-returns data as required and writes directly to the document stream


int fprintf (Resource $handle, String $format [, Mixed $args [, mixed $ ...])

Writes a string that is formatted according to format into the stream opened by the handle handle.

Get_html_translation_table-returning HTML entities that can be converted


Array get_html_translation_table ([int $table =html_specialchars [, int $flags = Ent_compat | ent_html401 [, String $encoding = ' UTF-8 ']])

Get_html_translation_table () returns the converted table after Htmlspecialchars () and htmlentities () processing.


Special characters can be used in a variety of ways. For example: " can be converted into ", & #34; or & #x22. Get_html_translation_table () returns one of the most commonly used.

hebrev-converting Hebrew encoded strings to visual text


String Hebrev (String $hebrew _text [, int $max _chars_per_line = 0])

Convert logical Order Hebrew (logical-hebrew) to Visual Order Hebrew (visual-hebrew)

The function will try to avoid breaking words.

hebrevc-converting Hebrew encoded strings to visual text


String Hebrevc (String $hebrew _text [, int $max _chars_per_line = 0])

The only difference between this function and Hebrev () is that this function converts additional line characters (\ n) to "<br>\n".

The function will try to avoid breaking words.

Inverse of the html_entity_decode-htmlentities () function to convert HTML entities to characters


String Html_entity_decode (string $string [, int $flags =ent_compat | ent_html401 [, String $encoding =ini_get ("Default_charset")])

Html_entity_decode () is htmlentities () instead, it puts all the HTML entities in the string with its applicable characteristics.

Rather, this function will necessarily effectively select the file type-that is, the XML, which does not decode entities that may be in some DTD definitions and B-named) characters in the character set with the selected encoding and is allowed in the selected file type, for all entities (including all numeric entities). All the other entities are left behind.

htmlentities-convert some characters in a string to HTML entities


String Htmlentities (string $string [, int $flags =ent_compat | ent_html401 [, String$encoding =ini_get ("Default_charset") [, BOOL $double _encode =true]])

This feature is Htmlspecialchars () in various ways the same, except Htmlentities (), all characters are translated into these entities as HTML character entity equivalents.

If you want to decode the opposite (reverse) you can use Html_entity_decode ().

Inverse of the htmlspecialchars_decode-htmlspecialchars () function to convert HTML entities to characters


String Htmlspecialchars_decode (string $string [, int $flags =ent_compat | ENT_HTML401])

This function is exactly the opposite of Htmlspecialchars (). It converts special HTML entities back to normal characters.

The entities being converted are: &amp;, &quot; (when no ent_noquotes is set), & #039; (set Ent_ QUOTES ), &lt; and &gt;.

htmlspecialchars-convert some characters in a string to HTML entities


String Htmlspecialchars (string $string [, int $flags =ent_compat | ent_html401 [, String$encoding =ini_get ("Default_charset") [, BOOL $double _encode =true]])

Some of the attributes in HTML have special meanings that should be given to HTML entities if they maintain their meaning. This function returns a string with these conversions. If you need to have the associated named entity translate all the substring of the input string, instead of using htmlentities ().

If the input string is passed to this function and the last file shares the same character set, this feature is fully prepared to contain the input most in an HTML document. If, however, the input can represent characters that are not encoded in the final Document character set, and you want to retain these characters (such as numbers or named entities), this feature and Htmlentities () (encoded only, named entity equivalents) may not be sufficient. You can use Mb_encode_numericentity () instead.

Translation methods:

' and ' (&) become "&amp;"

"" (double quotes) becomes ' &quot; when Ent_noquotes is not set.

"'" (single quote) becomes ' and # 039; "(or" only if ent_quotes is set;).

"<" (less than) becomes "<<"

">" (Greater Than) becomes ">"

implode-to convert an array to a string with a specific separator character


String implode (string $glue, array $pieces)

String implode (array $pieces)

join-convert an array to a string, alias of the Implode () function

levenshtein-Calculate the difference size of two words


int Levenshtein (String $str 1, String $str 2)

int Levenshtein (String $str 1, String $str 2, int $cost _ins, int $cost _rep, Int$cost_del)

Edit distance refers to the minimum number of characters required to str1 a string to be converted to a str2 by substitution, insertion, deletion, etc. between two strings. The complexity of the algorithm is O (m*n), where n and m are the lengths of str1 and str2 respectively (when and algorithm complexity is O (max (n,m) **3) Similar_text (), this function is quite good, although it is still time consuming. )。

In its simplest form, the function takes only two strings as arguments, and calculates the number of operations required to convert str1 to str2 by inserting, replacing, and deleting operations.

The second variant takes three additional parameters to define the number of INSERT, replace, and delete operations. This variant is more versatile and adaptable than the first, but less efficient.

localeconv-getting a number-related format definition


Array localeconv (void)

Returns an array that contains localized numeric and currency formatting information.

ltrim-to remove whitespace to the left of a string or to a specified character


String LTrim (String $str [, String $character _mask])

Remove whitespace characters (or other characters) at the beginning of a string

md5_file-a file for MD5 algorithm encryption


String Md5_file (String $filename [, bool $raw _output =false])

Calculates the MD5 hash value of the filename file and returns it using the»RSA data security Company's MD5 message algorithm. The hash value is a hexadecimal number of 32 characters.

md5-a string for MD5 algorithm encryption


String MD5 (string $str [, bool $raw _output =false])

The MD5 hash value of str is computed using the»RSA data security Company's MD5 message algorithm.

Metaphone-judging the pronunciation rules of a string


String Metaphone (string $str [, int $phonemes = 0])

Calculate the Metaphone key for a structure

Similar soundex () Metaphone Create the same key for pronouncing similar words. It is more accurate than soundex () because it understands the basic rules of English pronunciation. The key length generated by the Metaphone is variable.

Voice is developed by Lawrence at <<lphilips Philips Real dot com >. It describes the ["utility algorithm", Binstock & Rex, Eddison, 1995].

money_format-output of numbers formatted according to parameters


String Money_format (String $format, float)

Money_format () returns the version number of a format. The C library function of this feature Pack Strfmon (), this implementation will have only one number at a time difference.

nl_langinfo-querying language and local information

nl2br-replacing the newline character "\ n" in a string with "<br/>"

number_format-output of numbers formatted according to parameters

ord-converts an ASCII code to one character

parse_str-Convert a string of a certain format into a variable and a value

Print-used to output a single value

printf-data Display as required

Quoted_printable_decode-to encrypt a string into a 8-bit binary string

Quotemeta-to escape a number of specific characters

rtrim-remove whitespace to the right of a string or a specified character

setlocale-setting local formats for numbers, dates, and so on

sha1_file-a file for SHA1 algorithm encryption

Sha1-a string for SHA1 algorithm encryption

Similar_text-compares two strings and returns the number of similar characters that the system thinks

Soundex-judging the pronunciation rules of a string

The sprintf-returns the data as required, but does not output

sscanf-can format a string

str_ireplace-matches and replaces strings like the Str_replace () function, but is case insensitive

str_pad-padding on both sides of a string

str_repeat-repeating combinations of strings

str_replace-matching and replacing strings

str_rot13-string for ROT13 encryption processing

str_shuffle-random ordering of characters inside a string

str_split-splits a string into an array by character spacing

str_word_count-get the English word information inside the string

strcasecmp-size comparison of strings, case insensitive

Strchr-the alias of a partial strstr () function that returns a string by comparison

strcmp-size comparison of strings

strcoll– size comparison of strings based on local settings

strcspn-returns the value of a continuous non-matching length of characters

strip_tags-remove HTML and PHP code from a string

stripcslashes-inverse literal addcslashes () function escapes processed strings

Stripos-finds and returns the position of the first occurrence, matching is case-insensitive

stripslashes-inverse literal addslashes () function escapes processed strings

stristr-returns a portion of a string by comparison, case-insensitive compared

Strlen-gets the encoded length of a string

strnatcasecmp-the size comparison of strings using natural sorting, case-insensitive

strnatcmp-the size comparison of strings using the natural sort method

strncasecmp-size comparison of the first n characters of a string, case insensitive

strncmp-size comparison of the first n characters of a string

strpbrk-returns a portion of a string by comparison

strpos-Find and return the position of the first occurrence

strrchr-returns a part of a string by comparing it from backward to forward

strrev-all letters inside the string in reverse order

Strripos-finds and returns the position of the first match from the back, matching is case insensitive

strrpos– Find and return the position of the first match from behind

strspn-matches and returns the value of the character continuous occurrence length

strstr-returns a portion of a string by comparison

strtok-to split a string with a specified number of characters

strtolower-converting a string to lowercase

strtoupper– converting a string to uppercase

strtr-to string comparison substitution

Substr_compare-Comparison of strings after interception

substr_count-count occurrences of a character segment in a string

substr_replace-to replace part of a character in a string

substr-to intercept a string

trim-remove whitespace or specified characters on either side of a string

Ucfirst-converts the first letter of a given string to uppercase

ucwords-the first letter of each English word of the given string into uppercase

vfprintf-returns data as required and writes directly to the document stream

vprintf-data Display as required

The vsprintf-returns the data as required, but does not output

wordwrap-to divide a string by a certain character length

Summary of String functions

Related Article

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