Php string sorting method

Source: Internet
Author: User
Php string sorting method
This article describes how to organize php strings, including accessing a single character, deleting blank characters, and html escaping. For more information, see.

Php allows you to access, organize, and transcode strings in strings.

1. to access a single character in php, you can regard the string as an array of characters and directly access the string using the array access method. For example, $ str [0]. Note that if the character is not an ascii code, access may fail. Because such access can only get one byte.

2. delete blank characters in php. you can use trim (), ltrim (), and rtrim () functions to delete the white spaces starting or ending with a string. Trim () is used to delete the spaces before and after the characters; ltrim () is used to delete the white spaces on the left side of the characters; rtrim () is used to delete the white spaces on the right side of the characters. By default, the following characters are deleted: Space (| ox20), tab (\ n | ox09), line feed (\ n | oxoa), and press enter (\ r | 0x0d), empty characters (\ 0 | ox00 ). You can also specify it in the parameter.

3. use strtolower () to convert the entire string to lowercase. Strtoupper () converts the entire string to uppercase. Ucfirst () converts the first character of the string to uppercase, and other characters remain unchanged. Ucwords () converts the first character of each word in a string to uppercase, and other characters remain unchanged.

4. html escape refers to converting a string into a string used for html display. In this regard, php has two functions to implement this function. Htmlentities () converts all characters except spaces to html. Htmlspecialchars () converts necessary (with symbols &, double quotation marks, single quotes, greater than signs, less than signs) into html format.

5. url escape refers to converting a string into a url string. In this regard, php has two functions to implement this function. Urlencode () and urldecode () convert spaces into a plus sign, and convert other values into url strings. The former converts the space into a plus sign, and the latter converts rawurlencode () and rawurldecode () convert a space to % 20, that is, a normal url string. convert the space to a url string. convert the space to % 20, and convert the space to % 20.

6. SQL escaping the two most relevant databases (mysql and postgresql) of php are escape characters using backslashes (defined by oracle and not tested by other databases ), add the backslash using the addslashes () function in php and delete the backslash using the stripcslashes () function.

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.