String common functions, string functions

Source: Internet
Author: User
Tags chop

String common functions, string functions

// Specify the character list to escape all characters in the list
Addcslashes (string $ str, string $ charlist );

Echo addcslashes ('foo [] ', 'a. Z ');
// Output: \ f \ o \ [\]
// Escape all characters of the string foo [] ascii code between A and z
// Note: A-z cannot be written as z-A ascii code, which must be small to large.
// Echo addcslashes ('foo ['.'] ', 'z .. ');
// Output: \ zoo ['\.']


// Remove the backslash from the string
Stripcslashes

$ STR = <EOF
\\\\
EOF;
Echo $ STR;
//
Echo stripcslashes ($ STR );
/Escape the four escape characters into one/


// Escape '"\ by obtaining the value of php. ini magic_quotes_sybase
Addslashes (string $ str)

Magic_quotes_sybase = Off
$ Str = '\'"\';
Echo addslashes ($ str );
\'\"\\
Magic_quotes_sybase = On
$ Str = '\'"\';
Echo addslashes ($ str );
''" \ Test. php? Name = 'liukai'If (! Get_magic_quotes_gpc () {// detects php. Does the ini Enable Automatic escape of the get post cookie gpc get post cookie?Foreach ($ _ GET as & $ val ){$ Val = addslashes ($ val); // convert the get Array}}

// Remove the escape characters added by the string operated by addslashes based on the current value of magic_quotes_runtime
Stripaddslashes (string $ str)

Magic_quotes_sybase = On
$ Str = "''";
Echo stripaddslashes ($ str );
Output'

Magic_quotes_sybase = Off
$ Str = "\'\"\\";
Echo stripaddslashes ($ str );
Output '"\

// The rtrim alias function deletes all characters in the specified character list on the right of the string. By default, the character list contains only spaces.
Chop (string $ str [, string $ charlist])

Var_dump (chop ('123 '));
Output string (4) 123

Var_dump ('2017 C', 'C ');
Output string (5) 123

Var_dump ('1970 asw', 'swa ');
Output string (5) 123


// Return the specified character of the ascii code
Chr (int $ ascii)

Echo chr (97 );
Output

// Use this function to split a string into small pieces. For example, convert the base64_encode () output to a string that complies with the RFC 2045 syntax. It willChunklen(76 by default) characters inserted afterEnd(\ R \ n by default "). This function returns a new string without modifying the original string.
Chunk_split (string $ body, [, int$ Chunklen[, String$ End])
$ New_string = chunk_split (base64_encode ($ data); // converts the base64_encode () output to a string that complies with the RFC 2045 syntax.

// Returns the characters used by the string.
Count the number of occurrences of each byte value (0 .. 255) in String, and return results in multiple modes. The default value of mode is 0. Count_chars () returns the following results based on different modes:
0-an array with each byte value as the key name and number of occurrences as the value.
1-it is the same as 0, but only lists the byte values with occurrences greater than zero.
2-it is the same as 0, but only lists the byte values whose occurrences are equal to zero.
3-returns a string consisting of all byte values.
4-returns a string consisting of all unused byte values.
Count_chars (string $ str [, int $ mode])

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.